<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveRecord::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveRecord::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activerecord/lib/active_record/base_rb.html">
                vendor/rails/activerecord/lib/active_record/base.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Active Record objects don&#8216;t specify their <a
href="Base.html#M001758">attributes</a> directly, but rather infer them
from the table definition with which they&#8216;re linked. Adding,
removing, and changing <a href="Base.html#M001758">attributes</a> and their
type is done directly in the database. Any change is instantly reflected in
the Active Record objects. The mapping that binds a given Active Record
class to a certain database table will happen automatically in most common
cases, but can be overwritten for the uncommon ones.
</p>
<p>
See the mapping rules in <a href="Base.html#M001697">table_name</a> and the
full example in <a href="../../files/README.html">files/README.html</a> for
more insight.
</p>
<h2>Creation</h2>
<p>
Active Records accept constructor parameters either in a <a
href="Base.html#M001767">hash</a> or as a block. The <a
href="Base.html#M001767">hash</a> method is especially useful when
you&#8216;re receiving the data from somewhere else, like an HTTP request.
It works like this:
</p>
<pre>
  user = User.new(:name =&gt; &quot;David&quot;, :occupation =&gt; &quot;Code Artist&quot;)
  user.name # =&gt; &quot;David&quot;
</pre>
<p>
You can also use block initialization:
</p>
<pre>
  user = User.new do |u|
    u.name = &quot;David&quot;
    u.occupation = &quot;Code Artist&quot;
  end
</pre>
<p>
And of course you can just <a href="Base.html#M001680">create</a> a bare
object and specify the <a href="Base.html#M001758">attributes</a> after the
fact:
</p>
<pre>
  user = User.new
  user.name = &quot;David&quot;
  user.occupation = &quot;Code Artist&quot;
</pre>
<h2>Conditions</h2>
<p>
Conditions can either be specified as a string, array, or <a
href="Base.html#M001767">hash</a> representing the WHERE-part of an SQL
statement. The array form is to be used when the condition input is tainted
and requires sanitization. The string form can be used for statements that
don&#8216;t involve tainted data. The <a href="Base.html#M001767">hash</a>
form works much like the array form, except only equality and range is
possible. Examples:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    def self.authenticate_unsafely(user_name, password)
      find(:first, :conditions =&gt; &quot;user_name = '#{user_name}' AND password = '#{password}'&quot;)
    end

    def self.authenticate_safely(user_name, password)
      find(:first, :conditions =&gt; [ &quot;user_name = ? AND password = ?&quot;, user_name, password ])
    end

    def self.authenticate_safely_simply(user_name, password)
      find(:first, :conditions =&gt; { :user_name =&gt; user_name, :password =&gt; password })
    end
  end
</pre>
<p>
The <tt>authenticate_unsafely</tt> method inserts the parameters directly
into the query and is thus susceptible to SQL-injection attacks if the
<tt>user_name</tt> and <tt>password</tt> parameters come directly from an
HTTP request. The <tt>authenticate_safely</tt> and
<tt>authenticate_safely_simply</tt> both will sanitize the
<tt>user_name</tt> and <tt>password</tt> before inserting them in the
query, which will ensure that an attacker can&#8216;t escape the query and
fake the login (or worse).
</p>
<p>
When using multiple parameters in the conditions, it can easily become hard
to read exactly what the fourth or fifth question mark is supposed to
represent. In those cases, you can resort to named bind variables instead.
That&#8216;s done by replacing the question marks with symbols and
supplying a <a href="Base.html#M001767">hash</a> with values for the
matching symbol keys:
</p>
<pre>
  Company.find(:first, :conditions =&gt; [
    &quot;id = :id AND name = :name AND division = :division AND created_at &gt; :accounting_date&quot;,
    { :id =&gt; 3, :name =&gt; &quot;37signals&quot;, :division =&gt; &quot;First&quot;, :accounting_date =&gt; '2005-01-01' }
  ])
</pre>
<p>
Similarly, a simple <a href="Base.html#M001767">hash</a> without a
statement will generate conditions based on equality with the SQL AND
operator. For instance:
</p>
<pre>
  Student.find(:all, :conditions =&gt; { :first_name =&gt; &quot;Harvey&quot;, :status =&gt; 1 })
  Student.find(:all, :conditions =&gt; params[:student])
</pre>
<p>
A range may be used in the <a href="Base.html#M001767">hash</a> to use the
SQL BETWEEN operator:
</p>
<pre>
  Student.find(:all, :conditions =&gt; { :grade =&gt; 9..12 })
</pre>
<p>
An array may be used in the <a href="Base.html#M001767">hash</a> to use the
SQL IN operator:
</p>
<pre>
  Student.find(:all, :conditions =&gt; { :grade =&gt; [9,11,12] })
</pre>
<h2>Overwriting default accessors</h2>
<p>
All column values are automatically available through basic accessors on
the Active Record object, but sometimes you want to specialize this
behavior. This can be done by overwriting the default accessors (using the
same name as the attribute) and calling <tt>read_attribute(attr_name)</tt>
and <tt>write_attribute(attr_name, value)</tt> to actually change things.
Example:
</p>
<pre>
  class Song &lt; ActiveRecord::Base
    # Uses an integer of seconds to hold the length of the song

    def length=(minutes)
      write_attribute(:length, minutes.to_i * 60)
    end

    def length
      read_attribute(:length) / 60
    end
  end
</pre>
<p>
You can alternatively use <tt>self[:attribute]=(value)</tt> and
<tt>self[:attribute]</tt> instead of <tt>write_attribute(:attribute,
value)</tt> and <tt>read_attribute(:attribute)</tt> as a shorter form.
</p>
<h2>Attribute query methods</h2>
<p>
In addition to the basic accessors, query methods are also automatically
available on the Active Record object. Query methods allow you to test
whether an attribute value is present.
</p>
<p>
For example, an Active Record User with the <tt>name</tt> attribute has a
<tt>name?</tt> method that you can call to determine whether the user has a
name:
</p>
<pre>
  user = User.new(:name =&gt; &quot;David&quot;)
  user.name? # =&gt; true

  anonymous = User.new(:name =&gt; &quot;&quot;)
  anonymous.name? # =&gt; false
</pre>
<h2>Accessing <a href="Base.html#M001758">attributes</a> before they have been typecasted</h2>
<p>
Sometimes you want to be able to read the raw attribute data without having
the column-determined typecast run its course <a
href="Base.html#M001675">first</a>. That can be done by using the
<tt>&lt;attribute&gt;_before_type_cast</tt> accessors that <a
href="Base.html#M001677">all</a> <a href="Base.html#M001758">attributes</a>
have. For example, if your Account model has a <tt>balance</tt> attribute,
you can call <tt>account.balance_before_type_cast</tt> or
<tt>account.id_before_type_cast</tt>.
</p>
<p>
This is especially useful in validation situations where the user might
supply a string for an integer field and you want to display the original
string back in an error message. Accessing the attribute normally would
typecast the string to 0, which isn&#8216;t what you want.
</p>
<h2>Dynamic attribute-based finders</h2>
<p>
Dynamic attribute-based finders are a cleaner way of getting (and/or
creating) objects by simple queries without turning to SQL. They work by
appending the name of an attribute to <tt>find_by_</tt>,
<tt>find_last_by_</tt>, or <tt>find_all_by_</tt>, so you get finders like
<tt>Person.find_by_user_name</tt>, <tt>Person.find_all_by_last_name</tt>,
and <tt>Payment.find_by_transaction_id</tt>. So instead of writing
<tt>Person.find(:<a href="Base.html#M001675">first</a>, :conditions =&gt;
[&quot;user_name = ?&quot;, user_name])</tt>, you just do
<tt>Person.find_by_user_name(user_name)</tt>. And instead of writing
<tt>Person.find(:<a href="Base.html#M001677">all</a>, :conditions =&gt;
[&quot;last_name = ?&quot;, last_name])</tt>, you just do
<tt>Person.find_all_by_last_name(last_name)</tt>.
</p>
<p>
It&#8216;s also possible to use multiple <a
href="Base.html#M001758">attributes</a> in the same <a
href="Base.html#M001674">find</a> by separating them with
&quot;<em>and</em>&quot;, so you get finders like
<tt>Person.find_by_user_name_and_password</tt> or even
<tt>Payment.find_by_purchaser_and_state_and_country</tt>. So instead of
writing <tt>Person.find(:<a href="Base.html#M001675">first</a>, :conditions
=&gt; [&quot;user_name = ? AND password = ?&quot;, user_name,
password])</tt>, you just do
<tt>Person.find_by_user_name_and_password(user_name, password)</tt>.
</p>
<p>
It&#8216;s even possible to use <a href="Base.html#M001677">all</a> the
additional parameters to <a href="Base.html#M001674">find</a>. For example,
the full interface for <tt>Payment.find_all_by_amount</tt> is actually
<tt>Payment.find_all_by_amount(amount, options)</tt>. And the full
interface to <tt>Person.find_by_user_name</tt> is actually
<tt>Person.find_by_user_name(user_name, options)</tt>. So you could call
<tt>Payment.find_all_by_amount(50, :order =&gt;
&quot;created_on&quot;)</tt>. Also you may call
<tt>Payment.find_last_by_amount(amount, options)</tt> returning the <a
href="Base.html#M001676">last</a> record matching that amount and options.
</p>
<p>
The same dynamic finder style can be used to <a
href="Base.html#M001680">create</a> the object if it doesn&#8216;t already
exist. This dynamic finder is called with <tt>find_or_create_by_</tt> and
will return the object if it already exists and otherwise creates it, then
returns it. Protected <a href="Base.html#M001758">attributes</a>
won&#8216;t be set unless they are given in a block. For example:
</p>
<pre>
  # No 'Summer' tag exists
  Tag.find_or_create_by_name(&quot;Summer&quot;) # equal to Tag.create(:name =&gt; &quot;Summer&quot;)

  # Now the 'Summer' tag does exist
  Tag.find_or_create_by_name(&quot;Summer&quot;) # equal to Tag.find_by_name(&quot;Summer&quot;)

  # Now 'Bob' exist and is an 'admin'
  User.find_or_create_by_name('Bob', :age =&gt; 40) { |u| u.admin = true }
</pre>
<p>
Use the <tt>find_or_initialize_by_</tt> finder if you want to return a <a
href="Base.html#M001733">new</a> record without saving it <a
href="Base.html#M001675">first</a>. Protected <a
href="Base.html#M001758">attributes</a> won&#8216;t be set unless they are
given in a block. For example:
</p>
<pre>
  # No 'Winter' tag exists
  winter = Tag.find_or_initialize_by_name(&quot;Winter&quot;)
  winter.new_record? # true
</pre>
<p>
To <a href="Base.html#M001674">find</a> by a subset of the <a
href="Base.html#M001758">attributes</a> to be used for instantiating a <a
href="Base.html#M001733">new</a> object, pass a <a
href="Base.html#M001767">hash</a> instead of a list of parameters. For
example:
</p>
<pre>
  Tag.find_or_create_by_name(:name =&gt; &quot;rails&quot;, :creator =&gt; current_user)
</pre>
<p>
That will either <a href="Base.html#M001674">find</a> an existing tag named
&quot;rails&quot;, or <a href="Base.html#M001680">create</a> a <a
href="Base.html#M001733">new</a> one while setting the user that created
it.
</p>
<h2>Saving arrays, hashes, and other non-mappable objects in text <a href="Base.html#M001705">columns</a></h2>
<p>
Active Record can <a href="Base.html#M001695">serialize</a> any object in
text <a href="Base.html#M001705">columns</a> using YAML. To do so, you must
specify this with a call to the class method <tt><a
href="Base.html#M001695">serialize</a></tt>. This makes it possible to
store arrays, hashes, and other non-mappable objects without doing any
additional work. Example:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    serialize :preferences
  end

  user = User.create(:preferences =&gt; { &quot;background&quot; =&gt; &quot;black&quot;, &quot;display&quot; =&gt; large })
  User.find(user.id).preferences # =&gt; { &quot;background&quot; =&gt; &quot;black&quot;, &quot;display&quot; =&gt; large }
</pre>
<p>
You can also specify a class option as the second parameter that&#8216;ll
raise an exception if a serialized object is retrieved as a descendent of a
class not in the hierarchy. Example:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    serialize :preferences, Hash
  end

  user = User.create(:preferences =&gt; %w( one two three ))
  User.find(user.id).preferences    # raises SerializationTypeMismatch
</pre>
<h2>Single table inheritance</h2>
<p>
Active Record allows inheritance by storing the name of the class in a
column that by default is named &quot;type&quot; (can be changed by
overwriting <tt><a
href="Base.html#M001699">Base.inheritance_column</a></tt>). This means that
an inheritance looking like this:
</p>
<pre>
  class Company &lt; ActiveRecord::Base; end
  class Firm &lt; Company; end
  class Client &lt; Company; end
  class PriorityClient &lt; Client; end
</pre>
<p>
When you do <tt>Firm.create(:name =&gt; &quot;37signals&quot;)</tt>, this
record will be saved in the companies table with type = &quot;Firm&quot;.
You can then fetch this row again using <tt>Company.find(:<a
href="Base.html#M001675">first</a>, &quot;name =
&#8216;37signals&#8217;&quot;)</tt> and it will return a Firm object.
</p>
<p>
If you don&#8216;t have a type column defined in your table, single-table
inheritance won&#8216;t be triggered. In that case, it&#8216;ll work just
like normal subclasses with no special magic for differentiating between
them or reloading the right type with <a href="Base.html#M001674">find</a>.
</p>
<p>
Note, <a href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> for <a
href="Base.html#M001677">all</a> the cases are kept in the same table. Read
more: <a
href="http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html">www.martinfowler.com/eaaCatalog/singleTableInheritance.html</a>
</p>
<h2>Connection to multiple databases in different models</h2>
<p>
Connections are usually created through <a
href="Base.html#M001774">ActiveRecord::Base.establish_connection</a> and
retrieved by <a href="Base.html#M001773">ActiveRecord::Base.connection</a>.
All classes inheriting from <a href="Base.html">ActiveRecord::Base</a> will
use this <a href="Base.html#M001773">connection</a>. But you can also set a
class-specific <a href="Base.html#M001773">connection</a>. For example, if
Course is an <a href="Base.html">ActiveRecord::Base</a>, but resides in a
different database, you can just say <tt>Course.establish_connection</tt>
and Course and <a href="Base.html#M001677">all</a> of its subclasses will
use this <a href="Base.html#M001773">connection</a> instead.
</p>
<p>
This feature is implemented by keeping a <a
href="Base.html#M001773">connection</a> pool in <a
href="Base.html">ActiveRecord::Base</a> that is a Hash indexed by the
class. If a <a href="Base.html#M001773">connection</a> is requested, the <a
href="Base.html#M001781">retrieve_connection</a> method will go up the
class-hierarchy until a <a href="Base.html#M001773">connection</a> is found
in the <a href="Base.html#M001773">connection</a> pool.
</p>
<h2>Exceptions</h2>
<ul>
<li><a href="ActiveRecordError.html">ActiveRecordError</a> - Generic error
class and superclass of <a href="Base.html#M001677">all</a> other errors
raised by Active Record.

</li>
<li><a href="AdapterNotSpecified.html">AdapterNotSpecified</a> - The
configuration <a href="Base.html#M001767">hash</a> used in <tt><a
href="Base.html#M001774">establish_connection</a></tt> didn&#8216;t include
an <tt>:adapter</tt> key.

</li>
<li><a href="AdapterNotFound.html">AdapterNotFound</a> - The <tt>:adapter</tt>
key used in <tt><a href="Base.html#M001774">establish_connection</a></tt>
specified a non-existent adapter (or a bad spelling of an existing one).

</li>
<li><a href="AssociationTypeMismatch.html">AssociationTypeMismatch</a> - The
object assigned to the association wasn&#8216;t of the type specified in
the association definition.

</li>
<li><a href="SerializationTypeMismatch.html">SerializationTypeMismatch</a> -
The serialized object wasn&#8216;t of the class specified as the second
parameter.

</li>
<li><a href="ConnectionNotEstablished.html">ConnectionNotEstablished</a>+ - No
<a href="Base.html#M001773">connection</a> has been established. Use <tt><a
href="Base.html#M001774">establish_connection</a></tt> before querying.

</li>
<li><a href="RecordNotFound.html">RecordNotFound</a> - No record responded to
the <tt><a href="Base.html#M001674">find</a></tt> method. Either the row
with the given ID doesn&#8216;t exist or the row didn&#8216;t meet the
additional restrictions. Some <tt><a href="Base.html#M001674">find</a></tt>
calls do not raise this exception to signal nothing was found, please check
its documentation for further details.

</li>
<li><a href="StatementInvalid.html">StatementInvalid</a> - The database server
rejected the SQL statement. The precise error is added in the message.

</li>
<li><a
href="MultiparameterAssignmentErrors.html">MultiparameterAssignmentErrors</a>
- Collection of errors that occurred during a mass assignment using the
<tt><a href="Base.html#M001757">attributes=</a></tt> method. The
<tt>errors</tt> property of this exception contains an array of <a
href="AttributeAssignmentError.html">AttributeAssignmentError</a> objects
that should be inspected to determine which <a
href="Base.html#M001758">attributes</a> triggered the errors.

</li>
<li><a href="AttributeAssignmentError.html">AttributeAssignmentError</a> - An
error occurred while doing a mass assignment through the <tt><a
href="Base.html#M001757">attributes=</a></tt> method. You can <a
href="Base.html#M001713">inspect</a> the <tt>attribute</tt> property of the
exception object to determine which attribute triggered the error.

</li>
</ul>
<p>
<b>Note</b>: The <a href="Base.html#M001758">attributes</a> listed are
class-level <a href="Base.html#M001758">attributes</a> (accessible from
both the class and instance level). So it&#8216;s possible to assign a
logger to the class through <tt>Base.logger=</tt> which will then be used
by <a href="Base.html#M001677">all</a> instances in the current object
space.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001765">==</a>&nbsp;&nbsp;
      <a href="#M001716">===</a>&nbsp;&nbsp;
      <a href="#M001755">[]</a>&nbsp;&nbsp;
      <a href="#M001756">[]=</a>&nbsp;&nbsp;
      <a href="#M001718">abstract_class?</a>&nbsp;&nbsp;
      <a href="#M001728">aggregate_mapping</a>&nbsp;&nbsp;
      <a href="#M001677">all</a>&nbsp;&nbsp;
      <a href="#M001775">allow_concurrency</a>&nbsp;&nbsp;
      <a href="#M001776">allow_concurrency=</a>&nbsp;&nbsp;
      <a href="#M001692">attr_accessible</a>&nbsp;&nbsp;
      <a href="#M001691">attr_protected</a>&nbsp;&nbsp;
      <a href="#M001693">attr_readonly</a>&nbsp;&nbsp;
      <a href="#M001760">attribute_for_inspect</a>&nbsp;&nbsp;
      <a href="#M001763">attribute_names</a>&nbsp;&nbsp;
      <a href="#M001761">attribute_present?</a>&nbsp;&nbsp;
      <a href="#M001758">attributes</a>&nbsp;&nbsp;
      <a href="#M001757">attributes=</a>&nbsp;&nbsp;
      <a href="#M001759">attributes_before_type_cast</a>&nbsp;&nbsp;
      <a href="#M001717">base_class</a>&nbsp;&nbsp;
      <a href="#M001744">becomes</a>&nbsp;&nbsp;
      <a href="#M001714">benchmark</a>&nbsp;&nbsp;
      <a href="#M001736">cache_key</a>&nbsp;&nbsp;
      <a href="#M001725">class_of_active_record_descendant</a>&nbsp;&nbsp;
      <a href="#M001743">clone</a>&nbsp;&nbsp;
      <a href="#M001764">column_for_attribute</a>&nbsp;&nbsp;
      <a href="#M001707">column_names</a>&nbsp;&nbsp;
      <a href="#M001705">columns</a>&nbsp;&nbsp;
      <a href="#M001706">columns_hash</a>&nbsp;&nbsp;
      <a href="#M001724">compute_type</a>&nbsp;&nbsp;
      <a href="#M001782">connected?</a>&nbsp;&nbsp;
      <a href="#M001773">connection</a>&nbsp;&nbsp;
      <a href="#M001779">connection</a>&nbsp;&nbsp;
      <a href="#M001780">connection_pool</a>&nbsp;&nbsp;
      <a href="#M001708">content_columns</a>&nbsp;&nbsp;
      <a href="#M001687">count_by_sql</a>&nbsp;&nbsp;
      <a href="#M001680">create</a>&nbsp;&nbsp;
      <a href="#M001750">decrement</a>&nbsp;&nbsp;
      <a href="#M001751">decrement!</a>&nbsp;&nbsp;
      <a href="#M001690">decrement_counter</a>&nbsp;&nbsp;
      <a href="#M001682">delete</a>&nbsp;&nbsp;
      <a href="#M001741">delete</a>&nbsp;&nbsp;
      <a href="#M001686">delete_all</a>&nbsp;&nbsp;
      <a href="#M001712">descends_from_active_record?</a>&nbsp;&nbsp;
      <a href="#M001742">destroy</a>&nbsp;&nbsp;
      <a href="#M001683">destroy</a>&nbsp;&nbsp;
      <a href="#M001685">destroy_all</a>&nbsp;&nbsp;
      <a href="#M001766">eql?</a>&nbsp;&nbsp;
      <a href="#M001774">establish_connection</a>&nbsp;&nbsp;
      <a href="#M001679">exists?</a>&nbsp;&nbsp;
      <a href="#M001729">expand_hash_conditions_for_aggregates</a>&nbsp;&nbsp;
      <a href="#M001674">find</a>&nbsp;&nbsp;
      <a href="#M001678">find_by_sql</a>&nbsp;&nbsp;
      <a href="#M001675">first</a>&nbsp;&nbsp;
      <a href="#M001768">freeze</a>&nbsp;&nbsp;
      <a href="#M001769">frozen?</a>&nbsp;&nbsp;
      <a href="#M001762">has_attribute?</a>&nbsp;&nbsp;
      <a href="#M001767">hash</a>&nbsp;&nbsp;
      <a href="#M001710">human_attribute_name</a>&nbsp;&nbsp;
      <a href="#M001711">human_name</a>&nbsp;&nbsp;
      <a href="#M001734">id</a>&nbsp;&nbsp;
      <a href="#M001737">id=</a>&nbsp;&nbsp;
      <a href="#M001748">increment</a>&nbsp;&nbsp;
      <a href="#M001749">increment!</a>&nbsp;&nbsp;
      <a href="#M001689">increment_counter</a>&nbsp;&nbsp;
      <a href="#M001699">inheritance_column</a>&nbsp;&nbsp;
      <a href="#M001772">inspect</a>&nbsp;&nbsp;
      <a href="#M001713">inspect</a>&nbsp;&nbsp;
      <a href="#M001676">last</a>&nbsp;&nbsp;
      <a href="#M001721">merge_conditions</a>&nbsp;&nbsp;
      <a href="#M001733">new</a>&nbsp;&nbsp;
      <a href="#M001738">new_record?</a>&nbsp;&nbsp;
      <a href="#M001698">primary_key</a>&nbsp;&nbsp;
      <a href="#M001771">readonly!</a>&nbsp;&nbsp;
      <a href="#M001770">readonly?</a>&nbsp;&nbsp;
      <a href="#M001694">readonly_attributes</a>&nbsp;&nbsp;
      <a href="#M001754">reload</a>&nbsp;&nbsp;
      <a href="#M001783">remove_connection</a>&nbsp;&nbsp;
      <a href="#M001709">reset_column_information</a>&nbsp;&nbsp;
      <a href="#M001719">respond_to?</a>&nbsp;&nbsp;
      <a href="#M001781">retrieve_connection</a>&nbsp;&nbsp;
      <a href="#M001732">sanitize_sql_array</a>&nbsp;&nbsp;
      <a href="#M001727">sanitize_sql_for_assignment</a>&nbsp;&nbsp;
      <a href="#M001726">sanitize_sql_for_conditions</a>&nbsp;&nbsp;
      <a href="#M001731">sanitize_sql_hash_for_assignment</a>&nbsp;&nbsp;
      <a href="#M001730">sanitize_sql_hash_for_conditions</a>&nbsp;&nbsp;
      <a href="#M001739">save</a>&nbsp;&nbsp;
      <a href="#M001740">save!</a>&nbsp;&nbsp;
      <a href="#M001695">serialize</a>&nbsp;&nbsp;
      <a href="#M001696">serialized_attributes</a>&nbsp;&nbsp;
      <a href="#M001702">set_inheritance_column</a>&nbsp;&nbsp;
      <a href="#M001701">set_primary_key</a>&nbsp;&nbsp;
      <a href="#M001703">set_sequence_name</a>&nbsp;&nbsp;
      <a href="#M001700">set_table_name</a>&nbsp;&nbsp;
      <a href="#M001715">silence</a>&nbsp;&nbsp;
      <a href="#M001720">sti_name</a>&nbsp;&nbsp;
      <a href="#M001704">table_exists?</a>&nbsp;&nbsp;
      <a href="#M001697">table_name</a>&nbsp;&nbsp;
      <a href="#M001735">to_param</a>&nbsp;&nbsp;
      <a href="#M001752">toggle</a>&nbsp;&nbsp;
      <a href="#M001753">toggle!</a>&nbsp;&nbsp;
      <a href="#M001681">update</a>&nbsp;&nbsp;
      <a href="#M001684">update_all</a>&nbsp;&nbsp;
      <a href="#M001745">update_attribute</a>&nbsp;&nbsp;
      <a href="#M001746">update_attributes</a>&nbsp;&nbsp;
      <a href="#M001747">update_attributes!</a>&nbsp;&nbsp;
      <a href="#M001688">update_counters</a>&nbsp;&nbsp;
      <a href="#M001777">verification_timeout</a>&nbsp;&nbsp;
      <a href="#M001778">verification_timeout=</a>&nbsp;&nbsp;
      <a href="#M001723">with_exclusive_scope</a>&nbsp;&nbsp;
      <a href="#M001722">with_scope</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">VALID_FIND_OPTIONS</td>
          <td>=</td>
          <td class="context-item-value">[ :conditions, :include, :joins, :limit, :offset,                                :order, :select, :readonly, :group, :from, :lock ]</td>
        </tr>
        </table>
      </div>
    </div>

    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_table_name</td>
          <td>-&gt;</td>
          <td class="context-item-value">table_name=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_primary_key</td>
          <td>-&gt;</td>
          <td class="context-item-value">primary_key=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_inheritance_column</td>
          <td>-&gt;</td>
          <td class="context-item-value">inheritance_column=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">set_sequence_name</td>
          <td>-&gt;</td>
          <td class="context-item-value">sequence_name=</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql_for_conditions</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_sql</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql_hash_for_conditions</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_sql_hash</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sanitize_sql</td>
          <td>-&gt;</td>
          <td class="context-item-value">sanitize_conditions</td>
        </tr>
                        </table>
      </div>
    </div>


    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">abstract_class</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc">
Set this to true if this is an abstract class (see <tt><a
href="Base.html#M001718">abstract_class?</a></tt>).

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001716" class="method-detail">
        <a name="M001716"></a>

        <div class="method-heading">
          <a href="#M001716" class="method-signature">
          <span class="method-name">===</span><span class="method-args">(object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overwrite the default class equality method to provide support for
association proxies.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001716-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001716-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1404</span>
1404:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">===</span>(<span class="ruby-identifier">object</span>)
1405:         <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>)
1406:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001718" class="method-detail">
        <a name="M001718"></a>

        <div class="method-heading">
          <a href="#M001718" class="method-signature">
          <span class="method-name">abstract_class?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns whether this class is a base AR class. If A is a base class and B
descends from A, then B.base_class will return B.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001718-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001718-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1420</span>
1420:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">abstract_class?</span>
1421:         <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@abstract_class</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@abstract_class</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
1422:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001677" class="method-detail">
        <a name="M001677"></a>

        <div class="method-heading">
          <a href="#M001677" class="method-signature">
          <span class="method-name">all</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This is an alias for <a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001677">all</a>). You can pass in <a
href="Base.html#M001677">all</a> the same arguments to this method as you
can to <a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001677">all</a>)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001677-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001677-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 608</span>
608:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">all</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
609:         <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
610:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001775" class="method-detail">
        <a name="M001775"></a>

        <div class="method-heading">
          <a href="#M001775" class="method-signature">
          <span class="method-name">allow_concurrency</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deprecated and no longer has any effect.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001775-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001775-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 90</span>
90:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">allow_concurrency</span>
91:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-value str">&quot;ActiveRecord::Base.allow_concurrency has been deprecated and no longer has any effect. Please remove all references to allow_concurrency.&quot;</span>)
92:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001776" class="method-detail">
        <a name="M001776"></a>

        <div class="method-heading">
          <a href="#M001776" class="method-signature">
          <span class="method-name">allow_concurrency=</span><span class="method-args">(flag)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deprecated and no longer has any effect.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001776-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001776-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 95</span>
95:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">allow_concurrency=</span>(<span class="ruby-identifier">flag</span>)
96:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-value str">&quot;ActiveRecord::Base.allow_concurrency= has been deprecated and no longer has any effect. Please remove all references to allow_concurrency=.&quot;</span>)
97:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001692" class="method-detail">
        <a name="M001692"></a>

        <div class="method-heading">
          <a href="#M001692" class="method-signature">
          <span class="method-name">attr_accessible</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Specifies a white list of model <a href="Base.html#M001758">attributes</a>
that can be set via mass-assignment, such as <tt><a
href="Base.html#M001733">new</a>(<a
href="Base.html#M001758">attributes</a>)</tt>, <tt><a
href="Base.html#M001746">update_attributes</a>(<a
href="Base.html#M001758">attributes</a>)</tt>, or <tt><a
href="Base.html#M001757">attributes=</a>(<a
href="Base.html#M001758">attributes</a>)</tt>
</p>
<p>
This is the opposite of the <tt><a
href="Base.html#M001691">attr_protected</a></tt> macro: Mass-assignment
will only set <a href="Base.html#M001758">attributes</a> in this list, to
assign to the rest of <a href="Base.html#M001758">attributes</a> you can
use direct writer methods. This is meant to protect sensitive <a
href="Base.html#M001758">attributes</a> from being overwritten by malicious
users tampering with URLs or forms. If you&#8216;d rather start from an <a
href="Base.html#M001677">all</a>-open default and restrict <a
href="Base.html#M001758">attributes</a> as needed, have a look at <tt><a
href="Base.html#M001691">attr_protected</a></tt>.
</p>
<pre>
  class Customer &lt; ActiveRecord::Base
    attr_accessible :name, :nickname
  end

  customer = Customer.new(:name =&gt; &quot;David&quot;, :nickname =&gt; &quot;Dave&quot;, :credit_rating =&gt; &quot;Excellent&quot;)
  customer.credit_rating # =&gt; nil
  customer.attributes = { :name =&gt; &quot;Jolly fellow&quot;, :credit_rating =&gt; &quot;Superb&quot; }
  customer.credit_rating # =&gt; nil

  customer.credit_rating = &quot;Average&quot;
  customer.credit_rating # =&gt; &quot;Average&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001692-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001692-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1005</span>
1005:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_accessible</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
1006:         <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-identifier">:attr_accessible</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">accessible_attributes</span> <span class="ruby-operator">||</span> []))
1007:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001691" class="method-detail">
        <a name="M001691"></a>

        <div class="method-heading">
          <a href="#M001691" class="method-signature">
          <span class="method-name">attr_protected</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attributes named in this macro are protected from mass-assignment, such as
<tt><a href="Base.html#M001733">new</a>(<a
href="Base.html#M001758">attributes</a>)</tt>, <tt><a
href="Base.html#M001746">update_attributes</a>(<a
href="Base.html#M001758">attributes</a>)</tt>, or <tt><a
href="Base.html#M001757">attributes=</a>(<a
href="Base.html#M001758">attributes</a>)</tt>.
</p>
<p>
Mass-assignment to these <a href="Base.html#M001758">attributes</a> will
simply be ignored, to assign to them you can use direct writer methods.
This is meant to protect sensitive <a
href="Base.html#M001758">attributes</a> from being overwritten by malicious
users tampering with URLs or forms.
</p>
<pre>
  class Customer &lt; ActiveRecord::Base
    attr_protected :credit_rating
  end

  customer = Customer.new(&quot;name&quot; =&gt; David, &quot;credit_rating&quot; =&gt; &quot;Excellent&quot;)
  customer.credit_rating # =&gt; nil
  customer.attributes = { &quot;description&quot; =&gt; &quot;Jolly fellow&quot;, &quot;credit_rating&quot; =&gt; &quot;Superb&quot; }
  customer.credit_rating # =&gt; nil

  customer.credit_rating = &quot;Average&quot;
  customer.credit_rating # =&gt; &quot;Average&quot;
</pre>
<p>
To start from an <a href="Base.html#M001677">all</a>-closed default and
enable <a href="Base.html#M001758">attributes</a> as needed, have a look at
<tt><a href="Base.html#M001692">attr_accessible</a></tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001691-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001691-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 972</span>
972:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_protected</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
973:         <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-identifier">:attr_protected</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">protected_attributes</span> <span class="ruby-operator">||</span> []))
974:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001693" class="method-detail">
        <a name="M001693"></a>

        <div class="method-heading">
          <a href="#M001693" class="method-signature">
          <span class="method-name">attr_readonly</span><span class="method-args">(*attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attributes listed as readonly can be set for a <a
href="Base.html#M001733">new</a> record, but will be ignored in database
updates afterwards.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001693-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001693-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1015</span>
1015:        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attr_readonly</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attributes</span>)
1016:          <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-identifier">:attr_readonly</span>, <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">readonly_attributes</span> <span class="ruby-operator">||</span> []))
1017:        <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001717" class="method-detail">
        <a name="M001717"></a>

        <div class="method-heading">
          <a href="#M001717" class="method-signature">
          <span class="method-name">base_class</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the base AR subclass that this class descends from. If A extends
AR::Base, A.base_class will return A. If B descends from A through some
arbitrarily deep hierarchy, B.base_class will return A.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001717-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001717-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1411</span>
1411:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">base_class</span>
1412:         <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-keyword kw">self</span>)
1413:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001714" class="method-detail">
        <a name="M001714"></a>

        <div class="method-heading">
          <a href="#M001714" class="method-signature">
          <span class="method-name">benchmark</span><span class="method-args">(title, log_level = Logger::DEBUG, use_silence = true) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Log and <a href="Base.html#M001714">benchmark</a> multiple statements in a
single block. Example:
</p>
<pre>
  Project.benchmark(&quot;Creating project&quot;) do
    project = Project.create(&quot;name&quot; =&gt; &quot;stuff&quot;)
    project.create_manager(&quot;name&quot; =&gt; &quot;David&quot;)
    project.milestones &lt;&lt; Milestone.find(:all)
  end
</pre>
<p>
The <a href="Base.html#M001714">benchmark</a> is only recorded if the
current level of the logger is less than or equal to the
<tt>log_level</tt>, which makes it easy to include benchmarking statements
in production software that will remain inexpensive because the <a
href="Base.html#M001714">benchmark</a> will only be conducted if the log
level is low enough.
</p>
<p>
The logging of the multiple statements is turned off unless
<tt>use_silence</tt> is set to false.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001714-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001714-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1384</span>
1384:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">benchmark</span>(<span class="ruby-identifier">title</span>, <span class="ruby-identifier">log_level</span> = <span class="ruby-constant">Logger</span><span class="ruby-operator">::</span><span class="ruby-constant">DEBUG</span>, <span class="ruby-identifier">use_silence</span> = <span class="ruby-keyword kw">true</span>)
1385:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">log_level</span>
1386:           <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
1387:           <span class="ruby-identifier">seconds</span> = <span class="ruby-constant">Benchmark</span>.<span class="ruby-identifier">realtime</span> { <span class="ruby-identifier">result</span> = <span class="ruby-identifier">use_silence</span> <span class="ruby-value">? </span><span class="ruby-identifier">silence</span> { <span class="ruby-keyword kw">yield</span> } <span class="ruby-operator">:</span> <span class="ruby-keyword kw">yield</span> }
1388:           <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">log_level</span>, <span class="ruby-node">&quot;#{title} (#{'%.1f' % (seconds * 1000)}ms)&quot;</span>)
1389:           <span class="ruby-identifier">result</span>
1390:         <span class="ruby-keyword kw">else</span>
1391:           <span class="ruby-keyword kw">yield</span>
1392:         <span class="ruby-keyword kw">end</span>
1393:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001707" class="method-detail">
        <a name="M001707"></a>

        <div class="method-heading">
          <a href="#M001707" class="method-signature">
          <span class="method-name">column_names</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column names as strings.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001707-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001707-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1232</span>
1232:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">column_names</span>
1233:         <span class="ruby-ivar">@column_names</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span> }
1234:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001705" class="method-detail">
        <a name="M001705"></a>

        <div class="method-heading">
          <a href="#M001705" class="method-signature">
          <span class="method-name">columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column objects for the table associated with this
class.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001705-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001705-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1218</span>
1218:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns</span>
1219:         <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@columns</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@columns</span>
1220:           <span class="ruby-ivar">@columns</span> = <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">columns</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{name} Columns&quot;</span>)
1221:           <span class="ruby-ivar">@columns</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">primary</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">primary_key</span> }
1222:         <span class="ruby-keyword kw">end</span>
1223:         <span class="ruby-ivar">@columns</span>
1224:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001706" class="method-detail">
        <a name="M001706"></a>

        <div class="method-heading">
          <a href="#M001706" class="method-signature">
          <span class="method-name">columns_hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001767">hash</a> of column objects for the
table associated with this class.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001706-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001706-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1227</span>
1227:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns_hash</span>
1228:         <span class="ruby-ivar">@columns_hash</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">inject</span>({}) { <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">|</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">column</span>; <span class="ruby-identifier">hash</span> }
1229:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001782" class="method-detail">
        <a name="M001782"></a>

        <div class="method-heading">
          <a href="#M001782" class="method-signature">
          <span class="method-name">connected?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001782-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001782-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 124</span>
124:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connected?</span>
125:         <span class="ruby-identifier">connection_handler</span>.<span class="ruby-identifier">connected?</span>(<span class="ruby-keyword kw">self</span>)
126:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001779" class="method-detail">
        <a name="M001779"></a>

        <div class="method-heading">
          <a href="#M001779" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Base.html#M001773">connection</a> currently associated
with the class. This can also be used to &quot;borrow&quot; the <a
href="Base.html#M001773">connection</a> to do database work unrelated to
any of the specific Active Records.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001779-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001779-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 112</span>
112:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>
113:         <span class="ruby-identifier">retrieve_connection</span>
114:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001780" class="method-detail">
        <a name="M001780"></a>

        <div class="method-heading">
          <a href="#M001780" class="method-signature">
          <span class="method-name">connection_pool</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001780-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001780-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 116</span>
116:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection_pool</span>
117:         <span class="ruby-identifier">connection_handler</span>.<span class="ruby-identifier">retrieve_connection_pool</span>(<span class="ruby-keyword kw">self</span>)
118:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001708" class="method-detail">
        <a name="M001708"></a>

        <div class="method-heading">
          <a href="#M001708" class="method-signature">
          <span class="method-name">content_columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of column objects where the primary <a
href="Base.html#M001734">id</a>, <a href="Base.html#M001677">all</a> <a
href="Base.html#M001705">columns</a> ending in &quot;_id&quot; or
&quot;_count&quot;, and <a href="Base.html#M001705">columns</a> used for
single table inheritance have been removed.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001708-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001708-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1238</span>
1238:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_columns</span>
1239:         <span class="ruby-ivar">@content_columns</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">reject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">primary</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(_id|_count)$/</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">inheritance_column</span> }
1240:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001687" class="method-detail">
        <a name="M001687"></a>

        <div class="method-heading">
          <a href="#M001687" class="method-signature">
          <span class="method-name">count_by_sql</span><span class="method-args">(sql)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the result of an SQL statement that should only include a COUNT(*)
in the SELECT part. The use of this method should be restricted to
complicated SQL queries that can&#8216;t be executed using the
ActiveRecord::Calculations class methods. Look into those before using
this.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>sql</tt> - An SQL statement which should return a count query from the
database, see the example below.

</li>
</ul>
<h4>Examples</h4>
<pre>
  Product.count_by_sql &quot;SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001687-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001687-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 876</span>
876:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count_by_sql</span>(<span class="ruby-identifier">sql</span>)
877:         <span class="ruby-identifier">sql</span> = <span class="ruby-identifier">sanitize_conditions</span>(<span class="ruby-identifier">sql</span>)
878:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">select_value</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Count&quot;</span>).<span class="ruby-identifier">to_i</span>
879:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001680" class="method-detail">
        <a name="M001680"></a>

        <div class="method-heading">
          <a href="#M001680" class="method-signature">
          <span class="method-name">create</span><span class="method-args">(attributes = nil) {|object| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates an object (or multiple objects) and saves it to the database, if
validations pass. The resulting object is returned whether the object was
saved successfully to the database or not.
</p>
<p>
The <tt><a href="Base.html#M001758">attributes</a></tt> parameter can be
either be a Hash or an Array of Hashes. These Hashes describe the <a
href="Base.html#M001758">attributes</a> on the objects that are to be
created.
</p>
<h4>Examples</h4>
<pre>
  # Create a single new object
  User.create(:first_name =&gt; 'Jamie')

  # Create an Array of new objects
  User.create([{ :first_name =&gt; 'Jamie' }, { :first_name =&gt; 'Jeremy' }])

  # Create a single object and pass it into a block to set other attributes.
  User.create(:first_name =&gt; 'Jamie') do |u|
    u.is_admin = false
  end

  # Creating an Array of new objects using a block, where the block is executed for each object:
  User.create([{ :first_name =&gt; 'Jamie' }, { :first_name =&gt; 'Jeremy' }]) do |u|
    u.is_admin = false
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001680-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001680-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 687</span>
687:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">attributes</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
688:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
689:           <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) }
690:         <span class="ruby-keyword kw">else</span>
691:           <span class="ruby-identifier">object</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>)
692:           <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">object</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
693:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">save</span>
694:           <span class="ruby-identifier">object</span>
695:         <span class="ruby-keyword kw">end</span>
696:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001690" class="method-detail">
        <a name="M001690"></a>

        <div class="method-heading">
          <a href="#M001690" class="method-signature">
          <span class="method-name">decrement_counter</span><span class="method-args">(counter_name, id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decrement a number field by one, usually representing a count.
</p>
<p>
This works the same as <a href="Base.html#M001689">increment_counter</a>
but reduces the column value by 1 instead of increasing it.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>counter_name</tt> - The name of the field that should be decremented.

</li>
<li><tt><a href="Base.html#M001734">id</a></tt> - The <a
href="Base.html#M001734">id</a> of the object that should be decremented.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Decrement the post_count column for the record with an id of 5
  DiscussionBoard.decrement_counter(:post_count, 5)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001690-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001690-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 943</span>
943:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement_counter</span>(<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">id</span>)
944:         <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counter_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>)
945:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001682" class="method-detail">
        <a name="M001682"></a>

        <div class="method-heading">
          <a href="#M001682" class="method-signature">
          <span class="method-name">delete</span><span class="method-args">(id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delete an object (or multiple objects) where the <tt><a
href="Base.html#M001734">id</a></tt> given matches the <a
href="Base.html#M001698">primary_key</a>. A SQL <tt>DELETE</tt> command is
executed on the database which means that no callbacks are fired off
running this. This is an efficient method of deleting records that
don&#8216;t need cleaning up after or other actions to be taken.
</p>
<p>
Objects are <em>not</em> instantiated with this method, and so +:dependent+
rules defined on associations are not honered.
</p>
<h4>Parameters</h4>
<ul>
<li><tt><a href="Base.html#M001734">id</a></tt> - Can be either an Integer or
an Array of Integers.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Delete a single object
  Todo.delete(1)

  # Delete multiple objects
  todos = [1,2,3]
  Todo.delete(todos)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001682-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001682-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 744</span>
744:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">id</span>)
745:         <span class="ruby-identifier">delete_all</span>([ <span class="ruby-node">&quot;#{connection.quote_column_name(primary_key)} IN (?)&quot;</span>, <span class="ruby-identifier">id</span> ])
746:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001686" class="method-detail">
        <a name="M001686"></a>

        <div class="method-heading">
          <a href="#M001686" class="method-signature">
          <span class="method-name">delete_all</span><span class="method-args">(conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the records matching <tt>conditions</tt> without instantiating the
records <a href="Base.html#M001675">first</a>, and hence not calling the
<tt><a href="Base.html#M001683">destroy</a></tt> method nor invoking
callbacks. This is a single SQL DELETE statement that goes straight to the
database, much more efficient than <tt><a
href="Base.html#M001685">destroy_all</a></tt>. Be careful with relations
though, in particular <tt>:dependent</tt> rules defined on associations are
not honored.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>conditions</tt> - Conditions are specified the same way as with <tt><a
href="Base.html#M001674">find</a></tt> method.

</li>
</ul>
<h4>Example</h4>
<pre>
  Post.delete_all(&quot;person_id = 5 AND (category = 'Something' OR category = 'Else')&quot;)
  Post.delete_all([&quot;person_id = ? AND (category = ? OR category = ?)&quot;, 5, 'Something', 'Else'])
</pre>
<p>
Both calls <a href="Base.html#M001682">delete</a> the affected posts <a
href="Base.html#M001677">all</a> at once with a single DELETE statement. If
you need to <a href="Base.html#M001683">destroy</a> dependent associations
or call your <tt>before_*</tt> or <tt>after_destroy</tt> callbacks, use the
<tt><a href="Base.html#M001685">destroy_all</a></tt> method instead.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001686-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001686-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 859</span>
859:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_all</span>(<span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
860:         <span class="ruby-identifier">sql</span> = <span class="ruby-node">&quot;DELETE FROM #{quoted_table_name} &quot;</span>
861:         <span class="ruby-identifier">add_conditions!</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">scope</span>(<span class="ruby-identifier">:find</span>))
862:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Delete all&quot;</span>)
863:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001712" class="method-detail">
        <a name="M001712"></a>

        <div class="method-heading">
          <a href="#M001712" class="method-signature">
          <span class="method-name">descends_from_active_record?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if this isn&#8216;t a concrete subclass needing a STI type condition.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001712-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001712-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1334</span>
1334:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">descends_from_active_record?</span>
1335:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">abstract_class?</span>
1336:           <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">descends_from_active_record?</span>
1337:         <span class="ruby-keyword kw">else</span>
1338:           <span class="ruby-identifier">superclass</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">columns_hash</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">inheritance_column</span>)
1339:         <span class="ruby-keyword kw">end</span>
1340:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001683" class="method-detail">
        <a name="M001683"></a>

        <div class="method-heading">
          <a href="#M001683" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">(id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destroy an object (or multiple objects) that has the given <a
href="Base.html#M001734">id</a>, the object is instantiated <a
href="Base.html#M001675">first</a>, therefore <a
href="Base.html#M001677">all</a> callbacks and filters are fired off before
the object is deleted. This method is less efficient than
ActiveRecord#delete but allows cleanup methods and other actions to be run.
</p>
<p>
This essentially finds the object (or multiple objects) with the given <a
href="Base.html#M001734">id</a>, creates a <a
href="Base.html#M001733">new</a> object from the <a
href="Base.html#M001758">attributes</a>, and then calls <a
href="Base.html#M001683">destroy</a> on it.
</p>
<h4>Parameters</h4>
<ul>
<li><tt><a href="Base.html#M001734">id</a></tt> - Can be either an Integer or
an Array of Integers.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Destroy a single object
  Todo.destroy(1)

  # Destroy multiple objects
  todos = [1,2,3]
  Todo.destroy(todos)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001683-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001683-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 767</span>
767:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">id</span>)
768:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
769:           <span class="ruby-identifier">id</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">one_id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">one_id</span>) }
770:         <span class="ruby-keyword kw">else</span>
771:           <span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>).<span class="ruby-identifier">destroy</span>
772:         <span class="ruby-keyword kw">end</span>
773:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001685" class="method-detail">
        <a name="M001685"></a>

        <div class="method-heading">
          <a href="#M001685" class="method-signature">
          <span class="method-name">destroy_all</span><span class="method-args">(conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destroys the records matching <tt>conditions</tt> by instantiating each
record and calling their <tt><a href="Base.html#M001683">destroy</a></tt>
method. This means at least 2*N database queries to <a
href="Base.html#M001683">destroy</a> N records, so avoid <tt><a
href="Base.html#M001685">destroy_all</a></tt> if you are deleting many
records. If you want to simply <a href="Base.html#M001682">delete</a>
records without worrying about dependent associations or callbacks, use the
much faster <tt><a href="Base.html#M001686">delete_all</a></tt> method
instead.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>conditions</tt> - Conditions are specified the same way as with <tt><a
href="Base.html#M001674">find</a></tt> method.

</li>
</ul>
<h4>Example</h4>
<pre>
  Person.destroy_all(&quot;last_login &lt; '2004-04-04'&quot;)
</pre>
<p>
This loads and destroys each person one by one, including its dependent
associations and before_ and after_destroy callbacks.
</p>
<p>
<tt>conditions</tt> can be anything that <tt><a
href="Base.html#M001674">find</a></tt> also accepts:
</p>
<pre>
  Person.destroy_all(:last_login =&gt; 6.hours.ago)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001685-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001685-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 839</span>
839:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy_all</span>(<span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
840:         <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conditions</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">destroy</span> }
841:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001774" class="method-detail">
        <a name="M001774"></a>

        <div class="method-heading">
          <a href="#M001774" class="method-signature">
          <span class="method-name">establish_connection</span><span class="method-args">(spec = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Establishes the <a href="Base.html#M001773">connection</a> to the database.
Accepts a <a href="Base.html#M001767">hash</a> as input where the
<tt>:adapter</tt> key must be specified with the name of a database adapter
(in lower-case) example for regular databases (MySQL, Postgresql, etc):
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    :adapter  =&gt; &quot;mysql&quot;,
    :host     =&gt; &quot;localhost&quot;,
    :username =&gt; &quot;myuser&quot;,
    :password =&gt; &quot;mypass&quot;,
    :database =&gt; &quot;somedatabase&quot;
  )
</pre>
<p>
Example for SQLite database:
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    :adapter =&gt; &quot;sqlite&quot;,
    :database  =&gt; &quot;path/to/dbfile&quot;
  )
</pre>
<p>
Also accepts keys as strings (for parsing from YAML for example):
</p>
<pre>
  ActiveRecord::Base.establish_connection(
    &quot;adapter&quot; =&gt; &quot;sqlite&quot;,
    &quot;database&quot;  =&gt; &quot;path/to/dbfile&quot;
  )
</pre>
<p>
The exceptions <a href="AdapterNotSpecified.html">AdapterNotSpecified</a>,
<a href="AdapterNotFound.html">AdapterNotFound</a> and ArgumentError may be
returned on an error.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001774-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001774-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 49</span>
49:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">spec</span> = <span class="ruby-keyword kw">nil</span>)
50:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">spec</span>
51:         <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>
52:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-constant">RAILS_ENV</span>
53:           <span class="ruby-identifier">establish_connection</span>(<span class="ruby-constant">RAILS_ENV</span>)
54:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">ConnectionSpecification</span>
55:           <span class="ruby-ivar">@@connection_handler</span>.<span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">spec</span>)
56:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Symbol</span>, <span class="ruby-constant">String</span>
57:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">configuration</span> = <span class="ruby-identifier">configurations</span>[<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">to_s</span>]
58:             <span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">configuration</span>)
59:           <span class="ruby-keyword kw">else</span>
60:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span>, <span class="ruby-node">&quot;#{spec} database is not configured&quot;</span>
61:           <span class="ruby-keyword kw">end</span>
62:         <span class="ruby-keyword kw">else</span>
63:           <span class="ruby-identifier">spec</span> = <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">symbolize_keys</span>
64:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">:adapter</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotSpecified</span>, <span class="ruby-value str">&quot;database configuration does not specify adapter&quot;</span> <span class="ruby-keyword kw">end</span>
65: 
66:           <span class="ruby-keyword kw">begin</span>
67:             <span class="ruby-identifier">require</span> <span class="ruby-value str">'rubygems'</span>
68:             <span class="ruby-identifier">gem</span> <span class="ruby-node">&quot;activerecord-#{spec[:adapter]}-adapter&quot;</span>
69:             <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;active_record/connection_adapters/#{spec[:adapter]}_adapter&quot;</span>
70:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
71:             <span class="ruby-keyword kw">begin</span>
72:               <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;active_record/connection_adapters/#{spec[:adapter]}_adapter&quot;</span>
73:             <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">LoadError</span>
74:               <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{$!})&quot;</span>
75:             <span class="ruby-keyword kw">end</span>
76:           <span class="ruby-keyword kw">end</span>
77: 
78:           <span class="ruby-identifier">adapter_method</span> = <span class="ruby-node">&quot;#{spec[:adapter]}_connection&quot;</span>
79:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">adapter_method</span>)
80:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">AdapterNotFound</span>, <span class="ruby-node">&quot;database configuration specifies nonexistent #{spec[:adapter]} adapter&quot;</span>
81:           <span class="ruby-keyword kw">end</span>
82: 
83:           <span class="ruby-identifier">remove_connection</span>
84:           <span class="ruby-identifier">establish_connection</span>(<span class="ruby-constant">ConnectionSpecification</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">spec</span>, <span class="ruby-identifier">adapter_method</span>))
85:       <span class="ruby-keyword kw">end</span>
86:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001679" class="method-detail">
        <a name="M001679"></a>

        <div class="method-heading">
          <a href="#M001679" class="method-signature">
          <span class="method-name">exists?</span><span class="method-args">(id_or_conditions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks whether a record exists in the database that matches conditions
given. These conditions can either be a single integer representing a
primary key <a href="Base.html#M001734">id</a> to be found, or a condition
to be matched like using ActiveRecord#find.
</p>
<p>
The <tt>id_or_conditions</tt> parameter can be an Integer or a String if
you want to search the primary key column of the table for a matching <a
href="Base.html#M001734">id</a>, or if you&#8216;re looking to match
against a condition you can use an Array or a Hash.
</p>
<p>
Possible gotcha: You can&#8216;t pass in a condition as a string e.g.
&quot;name = &#8216;Jamie&#8217;&quot;, this would be sanitized and then
queried against the primary key column as &quot;<a
href="Base.html#M001734">id</a> = &#8216;name = \&#8217;Jamie&quot;
</p>
<h4>Examples</h4>
<pre>
  Person.exists?(5)
  Person.exists?('5')
  Person.exists?(:name =&gt; &quot;David&quot;)
  Person.exists?(['name LIKE ?', &quot;%#{query}%&quot;])
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001679-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001679-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 654</span>
654:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">id_or_conditions</span>)
655:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">select_all</span>(
656:           <span class="ruby-identifier">construct_finder_sql</span>(
657:             <span class="ruby-identifier">:select</span>     =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{quoted_table_name}.#{primary_key}&quot;</span>,
658:             <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">expand_id_conditions</span>(<span class="ruby-identifier">id_or_conditions</span>),
659:             <span class="ruby-identifier">:limit</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
660:           ),
661:           <span class="ruby-node">&quot;#{name} Exists&quot;</span>
662:         ).<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
663:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001674" class="method-detail">
        <a name="M001674"></a>

        <div class="method-heading">
          <a href="#M001674" class="method-signature">
          <span class="method-name">find</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Find operates with four different retrieval approaches:
</p>
<ul>
<li>Find by <a href="Base.html#M001734">id</a> - This can either be a specific
<a href="Base.html#M001734">id</a> (1), a list of ids (1, 5, 6), or an
array of ids ([5, 6, 10]). If no record can be found for <a
href="Base.html#M001677">all</a> of the listed ids, then <a
href="RecordNotFound.html">RecordNotFound</a> will be raised.

</li>
<li>Find <a href="Base.html#M001675">first</a> - This will return the <a
href="Base.html#M001675">first</a> record matched by the options used.
These options can either be specific conditions or merely an order. If no
record can be matched, <tt>nil</tt> is returned. Use <tt>Model.find(:<a
href="Base.html#M001675">first</a>, *args)</tt> or its shortcut
<tt>Model.first(*args)</tt>.

</li>
<li>Find <a href="Base.html#M001676">last</a> - This will return the <a
href="Base.html#M001676">last</a> record matched by the options used. These
options can either be specific conditions or merely an order. If no record
can be matched, <tt>nil</tt> is returned. Use <tt>Model.find(:<a
href="Base.html#M001676">last</a>, *args)</tt> or its shortcut
<tt>Model.last(*args)</tt>.

</li>
<li>Find <a href="Base.html#M001677">all</a> - This will return <a
href="Base.html#M001677">all</a> the records matched by the options used.
If no records are found, an empty array is returned. Use <tt>Model.find(:<a
href="Base.html#M001677">all</a>, *args)</tt> or its shortcut
<tt>Model.all(*args)</tt>.

</li>
</ul>
<p>
All approaches accept an options <a href="Base.html#M001767">hash</a> as
their <a href="Base.html#M001676">last</a> parameter.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>:conditions</tt> - An SQL fragment like &quot;administrator = 1&quot;,
<tt>[ &quot;user_name = ?&quot;, username ]</tt>, or <tt>[&quot;user_name =
:user_name&quot;, { :user_name =&gt; user_name }]</tt>. See conditions in
the intro.

</li>
<li><tt>:order</tt> - An SQL fragment like &quot;created_at DESC, name&quot;.

</li>
<li><tt>:group</tt> - An attribute name by which the result should be grouped.
Uses the <tt>GROUP BY</tt> SQL-clause.

</li>
<li><tt>:limit</tt> - An integer determining the limit on the number of rows
that should be returned.

</li>
<li><tt>:offset</tt> - An integer determining the offset from where the rows
should be fetched. So at 5, it would skip rows 0 through 4.

</li>
<li><tt>:joins</tt> - Either an SQL fragment for additional joins like
&quot;LEFT JOIN comments ON comments.post_id = <a
href="Base.html#M001734">id</a>&quot; (rarely needed) or named associations
in the same form used for the <tt>:include</tt> option, which will perform
an <tt>INNER JOIN</tt> on the associated table(s). If the value is a
string, then the records will be returned read-only since they will have <a
href="Base.html#M001758">attributes</a> that do not correspond to the
table&#8216;s <a href="Base.html#M001705">columns</a>. Pass <tt>:readonly
=&gt; false</tt> to override.

</li>
<li><tt>:include</tt> - Names associations that should be loaded alongside. The
symbols named refer to already defined associations. See eager loading
under Associations.

</li>
<li><tt>:select</tt> - By default, this is &quot;*&quot; as in &quot;SELECT *
FROM&quot;, but can be changed if you, for example, want to do a join but
not include the joined <a href="Base.html#M001705">columns</a>. Takes a
string with the SELECT SQL fragment (e.g. &quot;<a
href="Base.html#M001734">id</a>, name&quot;).

</li>
<li><tt>:from</tt> - By default, this is the table name of the class, but can
be changed to an alternate table name (or even the name of a database
view).

</li>
<li><tt>:readonly</tt> - Mark the returned records read-only so they cannot be
saved or updated.

</li>
<li><tt>:lock</tt> - An SQL fragment like &quot;FOR UPDATE&quot; or &quot;LOCK
IN SHARE MODE&quot;. <tt>:lock =&gt; true</tt> gives <a
href="Base.html#M001773">connection</a>&#8216;s default exclusive lock,
usually &quot;FOR UPDATE&quot;.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # find by id
  Person.find(1)       # returns the object for ID = 1
  Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
  Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
  Person.find([1])     # returns an array for the object with ID = 1
  Person.find(1, :conditions =&gt; &quot;administrator = 1&quot;, :order =&gt; &quot;created_on DESC&quot;)
</pre>
<p>
Note that returned records may not be in the same order as the ids you
provide since database rows are unordered. Give an explicit <tt>:order</tt>
to ensure the results are sorted.
</p>
<h4>Examples</h4>
<pre>
  # find first
  Person.find(:first) # returns the first object fetched by SELECT * FROM people
  Person.find(:first, :conditions =&gt; [ &quot;user_name = ?&quot;, user_name])
  Person.find(:first, :conditions =&gt; [ &quot;user_name = :u&quot;, { :u =&gt; user_name }])
  Person.find(:first, :order =&gt; &quot;created_on DESC&quot;, :offset =&gt; 5)

  # find last
  Person.find(:last) # returns the last object fetched by SELECT * FROM people
  Person.find(:last, :conditions =&gt; [ &quot;user_name = ?&quot;, user_name])
  Person.find(:last, :order =&gt; &quot;created_on DESC&quot;, :offset =&gt; 5)

  # find all
  Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people
  Person.find(:all, :conditions =&gt; [ &quot;category IN (?)&quot;, categories], :limit =&gt; 50)
  Person.find(:all, :conditions =&gt; { :friends =&gt; [&quot;Bob&quot;, &quot;Steve&quot;, &quot;Fred&quot;] }
  Person.find(:all, :offset =&gt; 10, :limit =&gt; 10)
  Person.find(:all, :include =&gt; [ :account, :friends ])
  Person.find(:all, :group =&gt; &quot;category&quot;)
</pre>
<p>
Example for <a href="Base.html#M001674">find</a> with a lock: Imagine two
concurrent transactions: each will read <tt>person.visits == 2</tt>, add 1
to it, and <a href="Base.html#M001739">save</a>, resulting in two saves of
<tt>person.visits = 3</tt>. By locking the row, the second transaction has
to wait until the <a href="Base.html#M001675">first</a> is finished; we get
the expected <tt>person.visits == 4</tt>.
</p>
<pre>
  Person.transaction do
    person = Person.find(1, :lock =&gt; true)
    person.visits += 1
    person.save!
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001674-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001674-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 581</span>
581:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
582:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
583:         <span class="ruby-identifier">validate_find_options</span>(<span class="ruby-identifier">options</span>)
584:         <span class="ruby-identifier">set_readonly_option!</span>(<span class="ruby-identifier">options</span>)
585: 
586:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>
587:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:first</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_initial</span>(<span class="ruby-identifier">options</span>)
588:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:last</span>  <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_last</span>(<span class="ruby-identifier">options</span>)
589:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:all</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_every</span>(<span class="ruby-identifier">options</span>)
590:           <span class="ruby-keyword kw">else</span>             <span class="ruby-identifier">find_from_ids</span>(<span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>)
591:         <span class="ruby-keyword kw">end</span>
592:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001678" class="method-detail">
        <a name="M001678"></a>

        <div class="method-heading">
          <a href="#M001678" class="method-signature">
          <span class="method-name">find_by_sql</span><span class="method-args">(sql)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Executes a custom SQL query against your database and returns <a
href="Base.html#M001677">all</a> the results. The results will be returned
as an array with <a href="Base.html#M001705">columns</a> requested
encapsulated as <a href="Base.html#M001758">attributes</a> of the model you
call this method from. If you call <tt>Product.find_by_sql</tt> then the
results will be returned in a Product object with the <a
href="Base.html#M001758">attributes</a> you specified in the SQL query.
</p>
<p>
If you call a complicated SQL query which spans multiple tables the <a
href="Base.html#M001705">columns</a> specified by the SELECT will be <a
href="Base.html#M001758">attributes</a> of the model, whether or not they
are <a href="Base.html#M001705">columns</a> of the corresponding table.
</p>
<p>
The <tt>sql</tt> parameter is a full SQL query as a string. It will be
called as is, there will be no database agnostic conversions performed.
This should be a <a href="Base.html#M001676">last</a> resort because using,
for example, MySQL specific terms will lock you to using that particular
database engine or require you to change your call if you switch engines.
</p>
<h4>Examples</h4>
<pre>
  # A simple SQL query spanning multiple tables
  Post.find_by_sql &quot;SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id&quot;
  &gt; [#&lt;Post:0x36bff9c @attributes={&quot;title&quot;=&gt;&quot;Ruby Meetup&quot;, &quot;first_name&quot;=&gt;&quot;Quentin&quot;}&gt;, ...]

  # You can use the same string replacement techniques as you can with ActiveRecord#find
  Post.find_by_sql [&quot;SELECT title FROM posts WHERE author = ? AND created &gt; ?&quot;, author_id, start_date]
  &gt; [#&lt;Post:0x36bff9c @attributes={&quot;first_name&quot;=&gt;&quot;The Cheap Man Buys Twice&quot;}&gt;, ...]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001678-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001678-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 634</span>
634:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_by_sql</span>(<span class="ruby-identifier">sql</span>)
635:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">select_all</span>(<span class="ruby-identifier">sanitize_sql</span>(<span class="ruby-identifier">sql</span>), <span class="ruby-node">&quot;#{name} Load&quot;</span>).<span class="ruby-identifier">collect!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">record</span><span class="ruby-operator">|</span> <span class="ruby-identifier">instantiate</span>(<span class="ruby-identifier">record</span>) }
636:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001675" class="method-detail">
        <a name="M001675"></a>

        <div class="method-heading">
          <a href="#M001675" class="method-signature">
          <span class="method-name">first</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A convenience wrapper for <tt><a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001675">first</a>, *args)</tt>. You can pass in <a
href="Base.html#M001677">all</a> the same arguments to this method as you
can to <tt><a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001675">first</a>)</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001675-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001675-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 596</span>
596:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">first</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
597:         <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
598:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001710" class="method-detail">
        <a name="M001710"></a>

        <div class="method-heading">
          <a href="#M001710" class="method-signature">
          <span class="method-name">human_attribute_name</span><span class="method-args">(attribute_key_name, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Transforms attribute key names into a more humane format, such as
&quot;First name&quot; instead of &quot;first_name&quot;. Example:
</p>
<pre>
  Person.human_attribute_name(&quot;first_name&quot;) # =&gt; &quot;First name&quot;
</pre>
<p>
This used to be depricated in favor of humanize, but is now preferred,
because it automatically uses the <a href="../I18n.html">I18n</a> module
now. Specify <tt>options</tt> with additional translating options.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001710-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001710-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1310</span>
1310:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">human_attribute_name</span>(<span class="ruby-identifier">attribute_key_name</span>, <span class="ruby-identifier">options</span> = {})
1311:         <span class="ruby-identifier">defaults</span> = <span class="ruby-identifier">self_and_descendents_from_active_record</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">klass</span><span class="ruby-operator">|</span>
1312:           <span class="ruby-node">&quot;#{klass.name.underscore}.#{attribute_key_name}&quot;</span><span class="ruby-node">&quot;#{klass.name.underscore}.#{attribute_key_name}&quot;</span>
1313:         <span class="ruby-keyword kw">end</span>
1314:         <span class="ruby-identifier">defaults</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:default</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:default</span>]
1315:         <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">flatten!</span>
1316:         <span class="ruby-identifier">defaults</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">attribute_key_name</span>.<span class="ruby-identifier">humanize</span>
1317:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:count</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">1</span>
1318:         <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">translate</span>(<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">shift</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">defaults</span>, <span class="ruby-identifier">:scope</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-identifier">:activerecord</span>, <span class="ruby-identifier">:attributes</span>]))
1319:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001711" class="method-detail">
        <a name="M001711"></a>

        <div class="method-heading">
          <a href="#M001711" class="method-signature">
          <span class="method-name">human_name</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Transform the modelname into a more humane format, using <a
href="../I18n.html">I18n</a>. Defaults to the basic humanize method.
Default scope of the translation is activerecord.models Specify
<tt>options</tt> with additional translating options.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001711-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001711-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1325</span>
1325:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">human_name</span>(<span class="ruby-identifier">options</span> = {})
1326:         <span class="ruby-identifier">defaults</span> = <span class="ruby-identifier">self_and_descendents_from_active_record</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">klass</span><span class="ruby-operator">|</span>
1327:           <span class="ruby-node">&quot;#{klass.name.underscore}&quot;</span><span class="ruby-node">&quot;#{klass.name.underscore}&quot;</span>
1328:         <span class="ruby-keyword kw">end</span> 
1329:         <span class="ruby-identifier">defaults</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">humanize</span>
1330:         <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">translate</span>(<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">shift</span>, {<span class="ruby-identifier">:scope</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-identifier">:activerecord</span>, <span class="ruby-identifier">:models</span>], <span class="ruby-identifier">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>, <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">defaults</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>))
1331:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001689" class="method-detail">
        <a name="M001689"></a>

        <div class="method-heading">
          <a href="#M001689" class="method-signature">
          <span class="method-name">increment_counter</span><span class="method-args">(counter_name, id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Increment a number field by one, usually representing a count.
</p>
<p>
This is used for caching aggregate values, so that they don&#8216;t need to
be computed every time. For example, a DiscussionBoard may cache post_count
and comment_count otherwise every time the board is shown it would have to
run an SQL query to <a href="Base.html#M001674">find</a> how many posts and
comments there are.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>counter_name</tt> - The name of the field that should be incremented.

</li>
<li><tt><a href="Base.html#M001734">id</a></tt> - The <a
href="Base.html#M001734">id</a> of the object that should be incremented.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Increment the post_count column for the record with an id of 5
  DiscussionBoard.increment_counter(:post_count, 5)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001689-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001689-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 926</span>
926:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment_counter</span>(<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">id</span>)
927:         <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counter_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>)
928:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001699" class="method-detail">
        <a name="M001699"></a>

        <div class="method-heading">
          <a href="#M001699" class="method-signature">
          <span class="method-name">inheritance_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Defines the column name for use with single table inheritance &#8212; can
be set in subclasses like so: self.inheritance_column = &quot;type_id&quot;
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001699-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001699-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1132</span>
1132:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inheritance_column</span>
1133:         <span class="ruby-ivar">@inheritance_column</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">&quot;type&quot;</span>.<span class="ruby-identifier">freeze</span>
1134:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001713" class="method-detail">
        <a name="M001713"></a>

        <div class="method-heading">
          <a href="#M001713" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a string like &#8216;Post <a
href="Base.html#M001734">id</a>:integer, title:string, body:text&#8216;
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001713-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001713-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1348</span>
1348:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
1349:         <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span>
1350:           <span class="ruby-keyword kw">super</span>
1351:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">abstract_class?</span>
1352:           <span class="ruby-node">&quot;#{super}(abstract)&quot;</span>
1353:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">table_exists?</span>
1354:           <span class="ruby-identifier">attr_list</span> = <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{c.name}: #{c.type}&quot;</span> } <span class="ruby-operator">*</span> <span class="ruby-value str">', '</span>
1355:           <span class="ruby-node">&quot;#{super}(#{attr_list})&quot;</span>
1356:         <span class="ruby-keyword kw">else</span>
1357:           <span class="ruby-node">&quot;#{super}(Table doesn't exist)&quot;</span>
1358:         <span class="ruby-keyword kw">end</span>
1359:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001676" class="method-detail">
        <a name="M001676"></a>

        <div class="method-heading">
          <a href="#M001676" class="method-signature">
          <span class="method-name">last</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A convenience wrapper for <tt><a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001676">last</a>, *args)</tt>. You can pass in <a
href="Base.html#M001677">all</a> the same arguments to this method as you
can to <tt><a href="Base.html#M001674">find</a>(:<a
href="Base.html#M001676">last</a>)</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001676-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001676-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 602</span>
602:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">last</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
603:         <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:last</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
604:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001721" class="method-detail">
        <a name="M001721"></a>

        <div class="method-heading">
          <a href="#M001721" class="method-signature">
          <span class="method-name">merge_conditions</span><span class="method-args">(*conditions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Merges conditions so that the result is a valid <tt>condition</tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001721-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001721-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1436</span>
1436:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge_conditions</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">conditions</span>)
1437:         <span class="ruby-identifier">segments</span> = []
1438: 
1439:         <span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">condition</span><span class="ruby-operator">|</span>
1440:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">condition</span>.<span class="ruby-identifier">blank?</span>
1441:             <span class="ruby-identifier">sql</span> = <span class="ruby-identifier">sanitize_sql</span>(<span class="ruby-identifier">condition</span>)
1442:             <span class="ruby-identifier">segments</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sql</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">sql</span>.<span class="ruby-identifier">blank?</span>
1443:           <span class="ruby-keyword kw">end</span>
1444:         <span class="ruby-keyword kw">end</span>
1445: 
1446:         <span class="ruby-node">&quot;(#{segments.join(') AND (')})&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">segments</span>.<span class="ruby-identifier">empty?</span>
1447:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001733" class="method-detail">
        <a name="M001733"></a>

        <div class="method-heading">
          <a href="#M001733" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(attributes = nil) {|self if block_given?| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
New objects can be instantiated as either empty (pass no construction
parameter) or pre-set with <a href="Base.html#M001758">attributes</a> but
not yet saved (pass a <a href="Base.html#M001767">hash</a> with key names
matching the associated table column names). In both instances, valid
attribute keys are determined by the column names of the associated table
&#8212; hence you can&#8216;t have <a
href="Base.html#M001758">attributes</a> that aren&#8216;t part of the table
<a href="Base.html#M001705">columns</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001733-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001733-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2280</span>
2280:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">attributes</span> = <span class="ruby-keyword kw">nil</span>)
2281:         <span class="ruby-ivar">@attributes</span> = <span class="ruby-identifier">attributes_from_column_definition</span>
2282:         <span class="ruby-ivar">@attributes_cache</span> = {}
2283:         <span class="ruby-ivar">@new_record</span> = <span class="ruby-keyword kw">true</span>
2284:         <span class="ruby-identifier">ensure_proper_type</span>
2285:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">nil?</span>
2286:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:scope</span>, <span class="ruby-identifier">:create</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">att</span>,<span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{att}=&quot;</span>, <span class="ruby-identifier">value</span>) } <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:scoped?</span>, <span class="ruby-identifier">:create</span>)
2287:         <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
2288:         <span class="ruby-identifier">callback</span>(<span class="ruby-identifier">:after_initialize</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to_without_attributes?</span>(<span class="ruby-identifier">:after_initialize</span>)
2289:         <span class="ruby-identifier">result</span>
2290:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001698" class="method-detail">
        <a name="M001698"></a>

        <div class="method-heading">
          <a href="#M001698" class="method-signature">
          <span class="method-name">primary_key</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Defines the primary key field &#8212; can be overridden in subclasses.
Overwriting will negate any effect of the primary_key_prefix_type setting,
though.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001698-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001698-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1109</span>
1109:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">primary_key</span>
1110:         <span class="ruby-identifier">reset_primary_key</span>
1111:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001694" class="method-detail">
        <a name="M001694"></a>

        <div class="method-heading">
          <a href="#M001694" class="method-signature">
          <span class="method-name">readonly_attributes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of <a href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> that have been specified as
readonly.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001694-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001694-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1020</span>
1020:        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly_attributes</span>
1021:          <span class="ruby-identifier">read_inheritable_attribute</span>(<span class="ruby-identifier">:attr_readonly</span>)
1022:        <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001783" class="method-detail">
        <a name="M001783"></a>

        <div class="method-heading">
          <a href="#M001783" class="method-signature">
          <span class="method-name">remove_connection</span><span class="method-args">(klass = self)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001783-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001783-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 128</span>
128:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_connection</span>(<span class="ruby-identifier">klass</span> = <span class="ruby-keyword kw">self</span>)
129:         <span class="ruby-identifier">connection_handler</span>.<span class="ruby-identifier">remove_connection</span>(<span class="ruby-identifier">klass</span>)
130:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001709" class="method-detail">
        <a name="M001709"></a>

        <div class="method-heading">
          <a href="#M001709" class="method-signature">
          <span class="method-name">reset_column_information</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Resets <a href="Base.html#M001677">all</a> the cached information about <a
href="Base.html#M001705">columns</a>, which will cause them to be reloaded
on the next request.
</p>
<p>
The most common usage pattern for this method is probably in a migration,
when just after creating a table you want to populate it with some default
values, eg:
</p>
<pre>
 class CreateJobLevels &lt; ActiveRecord::Migration
   def self.up
     create_table :job_levels do |t|
       t.integer :id
       t.string :name

       t.timestamps
     end

     JobLevel.reset_column_information
     %w{assistant executive manager director}.each do |type|
       JobLevel.create(:name =&gt; type)
     end
   end

   def self.down
     drop_table :job_levels
   end
 end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001709-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001709-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1282</span>
1282:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_column_information</span>
1283:         <span class="ruby-identifier">generated_methods</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">undef_method</span>(<span class="ruby-identifier">name</span>) }
1284:         <span class="ruby-ivar">@column_names</span> = <span class="ruby-ivar">@columns</span> = <span class="ruby-ivar">@columns_hash</span> = <span class="ruby-ivar">@content_columns</span> = <span class="ruby-ivar">@dynamic_methods_hash</span> = <span class="ruby-ivar">@generated_methods</span> = <span class="ruby-ivar">@inheritance_column</span> = <span class="ruby-keyword kw">nil</span>
1285:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001719" class="method-detail">
        <a name="M001719"></a>

        <div class="method-heading">
          <a href="#M001719" class="method-signature">
          <span class="method-name">respond_to?</span><span class="method-args">(method_id, include_private = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001719-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001719-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1424</span>
1424:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method_id</span>, <span class="ruby-identifier">include_private</span> = <span class="ruby-keyword kw">false</span>)
1425:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">match</span> = <span class="ruby-constant">DynamicFinderMatch</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">method_id</span>)
1426:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">all_attributes_exists?</span>(<span class="ruby-identifier">match</span>.<span class="ruby-identifier">attribute_names</span>)
1427:         <span class="ruby-keyword kw">end</span>
1428:         <span class="ruby-keyword kw">super</span>
1429:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001781" class="method-detail">
        <a name="M001781"></a>

        <div class="method-heading">
          <a href="#M001781" class="method-signature">
          <span class="method-name">retrieve_connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001781-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001781-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 120</span>
120:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">retrieve_connection</span>
121:         <span class="ruby-identifier">connection_handler</span>.<span class="ruby-identifier">retrieve_connection</span>(<span class="ruby-keyword kw">self</span>)
122:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001695" class="method-detail">
        <a name="M001695"></a>

        <div class="method-heading">
          <a href="#M001695" class="method-signature">
          <span class="method-name">serialize</span><span class="method-args">(attr_name, class_name = Object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
If you have an attribute that needs to be saved to the database as an
object, and retrieved as the same object, then specify the name of that
attribute using this method and it will be handled automatically. The
serialization is done through YAML. If <tt>class_name</tt> is specified,
the serialized object must be of that class on retrieval or <a
href="SerializationTypeMismatch.html">SerializationTypeMismatch</a> will be
raised.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>attr_name</tt> - The field name that should be serialized.

</li>
<li><tt>class_name</tt> - Optional, class name that the object type should be
equal to.

</li>
</ul>
<h4>Example</h4>
<pre>
  # Serialize a preferences attribute
  class User
    serialize :preferences
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001695-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001695-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1039</span>
1039:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serialize</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">class_name</span> = <span class="ruby-constant">Object</span>)
1040:         <span class="ruby-identifier">serialized_attributes</span>[<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">class_name</span>
1041:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001696" class="method-detail">
        <a name="M001696"></a>

        <div class="method-heading">
          <a href="#M001696" class="method-signature">
          <span class="method-name">serialized_attributes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001767">hash</a> of <a
href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> that have been specified for
serialization as keys and their class restriction as values.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001696-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001696-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1044</span>
1044:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serialized_attributes</span>
1045:         <span class="ruby-identifier">read_inheritable_attribute</span>(<span class="ruby-identifier">:attr_serialized</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-identifier">:attr_serialized</span>, {})
1046:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001702" class="method-detail">
        <a name="M001702"></a>

        <div class="method-heading">
          <a href="#M001702" class="method-signature">
          <span class="method-name">set_inheritance_column</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the inheritance column to use to the given value, or (if
the value # is nil or false) to the value returned by the given block.
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_inheritance_column do
      original_inheritance_column + &quot;_id&quot;
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001702-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001702-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1180</span>
1180:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_inheritance_column</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1181:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:inheritance_column</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1182:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001701" class="method-detail">
        <a name="M001701"></a>

        <div class="method-heading">
          <a href="#M001701" class="method-signature">
          <span class="method-name">set_primary_key</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the primary key column to use to the given value, or (if
the value is nil or false) to the value returned by the given block.
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_primary_key &quot;sysid&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001701-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001701-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1166</span>
1166:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_primary_key</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1167:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:primary_key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1168:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001703" class="method-detail">
        <a name="M001703"></a>

        <div class="method-heading">
          <a href="#M001703" class="method-signature">
          <span class="method-name">set_sequence_name</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the name of the sequence to use when generating ids to the given
value, or (if the value is nil or false) to the value returned by the given
block. This is required for Oracle and is useful for any database which
relies on sequences for primary key generation.
</p>
<p>
If a sequence name is not explicitly set when using Oracle or Firebird, it
will default to the commonly used pattern of: #{<a
href="Base.html#M001697">table_name</a>}_seq
</p>
<p>
If a sequence name is not explicitly set when using PostgreSQL, it will
discover the sequence corresponding to your primary key for you.
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_sequence_name &quot;projectseq&quot;   # default would have been &quot;project_seq&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001703-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001703-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1199</span>
1199:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_sequence_name</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1200:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:sequence_name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1201:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001700" class="method-detail">
        <a name="M001700"></a>

        <div class="method-heading">
          <a href="#M001700" class="method-signature">
          <span class="method-name">set_table_name</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the table name to use to the given value, or (if the value is nil or
false) to the value returned by the given block.
</p>
<pre>
  class Project &lt; ActiveRecord::Base
    set_table_name &quot;project&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001700-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001700-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1154</span>
1154:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_table_name</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1155:         <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:table_name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
1156:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001715" class="method-detail">
        <a name="M001715"></a>

        <div class="method-heading">
          <a href="#M001715" class="method-signature">
          <span class="method-name">silence</span><span class="method-args">() {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Silences the logger for the duration of the block.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001715-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001715-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1396</span>
1396:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">silence</span>
1397:         <span class="ruby-identifier">old_logger_level</span>, <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> = <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span>, <span class="ruby-constant">Logger</span><span class="ruby-operator">::</span><span class="ruby-constant">ERROR</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span>
1398:         <span class="ruby-keyword kw">yield</span>
1399:       <span class="ruby-keyword kw">ensure</span>
1400:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span> = <span class="ruby-identifier">old_logger_level</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span>
1401:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001720" class="method-detail">
        <a name="M001720"></a>

        <div class="method-heading">
          <a href="#M001720" class="method-signature">
          <span class="method-name">sti_name</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001720-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001720-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1431</span>
1431:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sti_name</span>
1432:         <span class="ruby-identifier">store_full_sti_class</span> <span class="ruby-value">? </span><span class="ruby-identifier">name</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">demodulize</span>
1433:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001704" class="method-detail">
        <a name="M001704"></a>

        <div class="method-heading">
          <a href="#M001704" class="method-signature">
          <span class="method-name">table_exists?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Indicates whether the table associated with this class exists
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001704-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001704-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1213</span>
1213:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">table_exists?</span>
1214:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">table_exists?</span>(<span class="ruby-identifier">table_name</span>)
1215:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001697" class="method-detail">
        <a name="M001697"></a>

        <div class="method-heading">
          <a href="#M001697" class="method-signature">
          <span class="method-name">table_name</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Guesses the table name (in forced lower-case) based on the name of the
class in the inheritance hierarchy descending directly from <a
href="Base.html">ActiveRecord::Base</a>. So if the hierarchy looks like:
Reply &lt; Message &lt; <a href="Base.html">ActiveRecord::Base</a>, then
Message is used to guess the table name even when called on Reply. The
rules used to do the guess are handled by the Inflector class in Active
Support, which knows almost <a href="Base.html#M001677">all</a> common
English inflections. You can add <a href="Base.html#M001733">new</a>
inflections in config/initializers/inflections.rb.
</p>
<p>
Nested classes are given table names prefixed by the singular form of the
parent&#8216;s table name. Enclosing modules are not considered.
</p>
<h4>Examples</h4>
<pre>
  class Invoice &lt; ActiveRecord::Base; end;
  file                  class               table_name
  invoice.rb            Invoice             invoices

  class Invoice &lt; ActiveRecord::Base; class Lineitem &lt; ActiveRecord::Base; end; end;
  file                  class               table_name
  invoice.rb            Invoice::Lineitem   invoice_lineitems

  module Invoice; class Lineitem &lt; ActiveRecord::Base; end; end;
  file                  class               table_name
  invoice/lineitem.rb   Invoice::Lineitem   lineitems
</pre>
<p>
Additionally, the class-level <tt>table_name_prefix</tt> is prepended and
the <tt>table_name_suffix</tt> is appended. So if you have
&quot;myapp_&quot; as a prefix, the table name guess for an Invoice class
<a href="Base.html#M001744">becomes</a> &quot;myapp_invoices&quot;.
Invoice::Lineitem <a href="Base.html#M001744">becomes</a>
&quot;myapp_invoice_lineitems&quot;.
</p>
<p>
You can also overwrite this class method to allow for unguessable links,
such as a Mouse class with a link to a &quot;mice&quot; table. Example:
</p>
<pre>
  class Mouse &lt; ActiveRecord::Base
    set_table_name &quot;mice&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001697-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001697-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1082</span>
1082:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">table_name</span>
1083:         <span class="ruby-identifier">reset_table_name</span>
1084:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001681" class="method-detail">
        <a name="M001681"></a>

        <div class="method-heading">
          <a href="#M001681" class="method-signature">
          <span class="method-name">update</span><span class="method-args">(id, attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates an object (or multiple objects) and saves it to the database, if
validations pass. The resulting object is returned whether the object was
saved successfully to the database or not.
</p>
<h4>Parameters</h4>
<ul>
<li><tt><a href="Base.html#M001734">id</a></tt> - This should be the <a
href="Base.html#M001734">id</a> or an array of ids to be updated.

</li>
<li><tt><a href="Base.html#M001758">attributes</a></tt> - This should be a Hash
of <a href="Base.html#M001758">attributes</a> to be set on the object, or
an array of Hashes.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Updating one record:
  Person.update(15, { :user_name =&gt; 'Samuel', :group =&gt; 'expert' })

  # Updating multiple records:
  people = { 1 =&gt; { &quot;first_name&quot; =&gt; &quot;David&quot; }, 2 =&gt; { &quot;first_name&quot; =&gt; &quot;Jeremy&quot; } }
  Person.update(people.keys, people.values)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001681-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001681-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 714</span>
714:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">attributes</span>)
715:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
716:           <span class="ruby-identifier">idx</span> = <span class="ruby-value">-1</span>
717:           <span class="ruby-identifier">id</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">one_id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>; <span class="ruby-identifier">update</span>(<span class="ruby-identifier">one_id</span>, <span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">idx</span>]) }
718:         <span class="ruby-keyword kw">else</span>
719:           <span class="ruby-identifier">object</span> = <span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>)
720:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">attributes</span>)
721:           <span class="ruby-identifier">object</span>
722:         <span class="ruby-keyword kw">end</span>
723:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001684" class="method-detail">
        <a name="M001684"></a>

        <div class="method-heading">
          <a href="#M001684" class="method-signature">
          <span class="method-name">update_all</span><span class="method-args">(updates, conditions = nil, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates <a href="Base.html#M001677">all</a> records with details given if
they match a set of conditions supplied, limits and order can also be
supplied. This method constructs a single SQL UPDATE statement and sends it
straight to the database. It does not instantiate the involved models and
it does not trigger Active Record callbacks.
</p>
<h4>Parameters</h4>
<ul>
<li><tt>updates</tt> - A string of column and value pairs that will be set on
any records that match conditions.

<pre>
            What goes into the SET clause.
</pre>
</li>
<li><tt>conditions</tt> - An SQL fragment like &quot;administrator = 1&quot; or
[ &quot;user_name = ?&quot;, username ]. See conditions in the intro for
more info.

</li>
<li><tt>options</tt> - Additional options are <tt>:limit</tt> and
<tt>:order</tt>, see the examples for usage.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # Update all billing objects with the 3 different attributes given
  Billing.update_all( &quot;category = 'authorized', approved = 1, author = 'David'&quot; )

  # Update records that match our conditions
  Billing.update_all( &quot;author = 'David'&quot;, &quot;title LIKE '%Rails%'&quot; )

  # Update records that match our conditions but limit it to 5 ordered by date
  Billing.update_all( &quot;author = 'David'&quot;, &quot;title LIKE '%Rails%'&quot;,
                        :order =&gt; 'created_at', :limit =&gt; 5 )
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001684-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001684-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 797</span>
797:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_all</span>(<span class="ruby-identifier">updates</span>, <span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = {})
798:         <span class="ruby-identifier">sql</span>  = <span class="ruby-node">&quot;UPDATE #{quoted_table_name} SET #{sanitize_sql_for_assignment(updates)} &quot;</span>
799: 
800:         <span class="ruby-identifier">scope</span> = <span class="ruby-identifier">scope</span>(<span class="ruby-identifier">:find</span>)
801: 
802:         <span class="ruby-identifier">select_sql</span> = <span class="ruby-value str">&quot;&quot;</span>
803:         <span class="ruby-identifier">add_conditions!</span>(<span class="ruby-identifier">select_sql</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">scope</span>)
804: 
805:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:limit</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">scope</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">scope</span>[<span class="ruby-identifier">:limit</span>])
806:           <span class="ruby-comment cmt"># Only take order from scope if limit is also provided by scope, this</span>
807:           <span class="ruby-comment cmt"># is useful for updating a has_many association with a limit.</span>
808:           <span class="ruby-identifier">add_order!</span>(<span class="ruby-identifier">select_sql</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:order</span>], <span class="ruby-identifier">scope</span>)
809: 
810:           <span class="ruby-identifier">add_limit!</span>(<span class="ruby-identifier">select_sql</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">scope</span>)
811:           <span class="ruby-identifier">sql</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">limited_update_conditions</span>(<span class="ruby-identifier">select_sql</span>, <span class="ruby-identifier">quoted_table_name</span>, <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">primary_key</span>)))
812:         <span class="ruby-keyword kw">else</span>
813:           <span class="ruby-identifier">add_order!</span>(<span class="ruby-identifier">select_sql</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:order</span>], <span class="ruby-keyword kw">nil</span>)
814:           <span class="ruby-identifier">sql</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">select_sql</span>)
815:         <span class="ruby-keyword kw">end</span>
816: 
817:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-node">&quot;#{name} Update&quot;</span>)
818:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001688" class="method-detail">
        <a name="M001688"></a>

        <div class="method-heading">
          <a href="#M001688" class="method-signature">
          <span class="method-name">update_counters</span><span class="method-args">(id, counters)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A generic &quot;counter updater&quot; implementation, intended primarily to
be used by <a href="Base.html#M001689">increment_counter</a> and <a
href="Base.html#M001690">decrement_counter</a>, but which may also be
useful on its own. It simply does a direct SQL <a
href="Base.html#M001681">update</a> for the record with the given ID,
altering the given <a href="Base.html#M001767">hash</a> of counters by the
amount given by the corresponding value:
</p>
<h4>Parameters</h4>
<ul>
<li><tt><a href="Base.html#M001734">id</a></tt> - The <a
href="Base.html#M001734">id</a> of the object you wish to <a
href="Base.html#M001681">update</a> a counter on.

</li>
<li><tt>counters</tt> - An Array of Hashes containing the names of the fields
to <a href="Base.html#M001681">update</a> as keys and the amount to <a
href="Base.html#M001681">update</a> the field by as values.

</li>
</ul>
<h4>Examples</h4>
<pre>
  # For the Post with id of 5, decrement the comment_count by 1, and
  # increment the action_count by 1
  Post.update_counters 5, :comment_count =&gt; -1, :action_count =&gt; 1
  # Executes the following SQL:
  # UPDATE posts
  #    SET comment_count = comment_count - 1,
  #        action_count = action_count + 1
  #  WHERE id = 5
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001688-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001688-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 903</span>
903:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_counters</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
904:         <span class="ruby-identifier">updates</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">inject</span>([]) { <span class="ruby-operator">|</span><span class="ruby-identifier">list</span>, (<span class="ruby-identifier">counter_name</span>, <span class="ruby-identifier">increment</span>)<span class="ruby-operator">|</span>
905:           <span class="ruby-identifier">sign</span> = <span class="ruby-identifier">increment</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;+&quot;</span>
906:           <span class="ruby-identifier">list</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{connection.quote_column_name(counter_name)} = COALESCE(#{connection.quote_column_name(counter_name)}, 0) #{sign} #{increment.abs}&quot;</span>
907:         }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;, &quot;</span>)
908:         <span class="ruby-identifier">update_all</span>(<span class="ruby-identifier">updates</span>, <span class="ruby-node">&quot;#{connection.quote_column_name(primary_key)} = #{quote_value(id)}&quot;</span>)
909:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001777" class="method-detail">
        <a name="M001777"></a>

        <div class="method-heading">
          <a href="#M001777" class="method-signature">
          <span class="method-name">verification_timeout</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deprecated and no longer has any effect.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001777-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001777-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 100</span>
100:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">verification_timeout</span>
101:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-value str">&quot;ActiveRecord::Base.verification_timeout has been deprecated and no longer has any effect. Please remove all references to verification_timeout.&quot;</span>)
102:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001778" class="method-detail">
        <a name="M001778"></a>

        <div class="method-heading">
          <a href="#M001778" class="method-signature">
          <span class="method-name">verification_timeout=</span><span class="method-args">(flag)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deprecated and no longer has any effect.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001778-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001778-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 105</span>
105:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">verification_timeout=</span>(<span class="ruby-identifier">flag</span>)
106:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-value str">&quot;ActiveRecord::Base.verification_timeout= has been deprecated and no longer has any effect. Please remove all references to verification_timeout=.&quot;</span>)
107:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Class methods</h3>

      <div id="method-M001728" class="method-detail">
        <a name="M001728"></a>

        <div class="method-heading">
          <a href="#M001728" class="method-signature">
          <span class="method-name">aggregate_mapping</span><span class="method-args">(reflection)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001728-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001728-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2099</span>
2099:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">aggregate_mapping</span>(<span class="ruby-identifier">reflection</span>)
2100:           <span class="ruby-identifier">mapping</span> = <span class="ruby-identifier">reflection</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:mapping</span>] <span class="ruby-operator">||</span> [<span class="ruby-identifier">reflection</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">reflection</span>.<span class="ruby-identifier">name</span>]
2101:           <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">mapping</span> <span class="ruby-operator">:</span> [<span class="ruby-identifier">mapping</span>]
2102:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001725" class="method-detail">
        <a name="M001725"></a>

        <div class="method-heading">
          <a href="#M001725" class="method-signature">
          <span class="method-name">class_of_active_record_descendant</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the class descending directly from Active Record in the inheritance
hierarchy.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001725-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001725-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2057</span>
2057:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-identifier">klass</span>)
2058:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Base</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">abstract_class?</span>
2059:             <span class="ruby-identifier">klass</span>
2060:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">nil?</span>
2061:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-node">&quot;#{name} doesn't belong in a hierarchy descending from ActiveRecord&quot;</span>
2062:           <span class="ruby-keyword kw">else</span>
2063:             <span class="ruby-identifier">class_of_active_record_descendant</span>(<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>)
2064:           <span class="ruby-keyword kw">end</span>
2065:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001724" class="method-detail">
        <a name="M001724"></a>

        <div class="method-heading">
          <a href="#M001724" class="method-signature">
          <span class="method-name">compute_type</span><span class="method-args">(type_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the class type of the record using the current module as a prefix.
So descendents of MyApp::Business::Account would appear as
MyApp::Business::AccountSubclass.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001724-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001724-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2045</span>
2045:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compute_type</span>(<span class="ruby-identifier">type_name</span>)
2046:           <span class="ruby-identifier">modularized_name</span> = <span class="ruby-identifier">type_name_with_module</span>(<span class="ruby-identifier">type_name</span>)
2047:           <span class="ruby-identifier">silence_warnings</span> <span class="ruby-keyword kw">do</span>
2048:             <span class="ruby-keyword kw">begin</span>
2049:               <span class="ruby-identifier">class_eval</span>(<span class="ruby-identifier">modularized_name</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>)
2050:             <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
2051:               <span class="ruby-identifier">class_eval</span>(<span class="ruby-identifier">type_name</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span>)
2052:             <span class="ruby-keyword kw">end</span>
2053:           <span class="ruby-keyword kw">end</span>
2054:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001729" class="method-detail">
        <a name="M001729"></a>

        <div class="method-heading">
          <a href="#M001729" class="method-signature">
          <span class="method-name">expand_hash_conditions_for_aggregates</span><span class="method-args">(attrs)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts a <a href="Base.html#M001767">hash</a> of SQL conditions and
replaces those <a href="Base.html#M001758">attributes</a> that correspond
to a <tt>composed_of</tt> relationship with their expanded aggregate
attribute values. Given:
</p>
<pre>
    class Person &lt; ActiveRecord::Base
      composed_of :address, :class_name =&gt; &quot;Address&quot;,
        :mapping =&gt; [%w(address_street street), %w(address_city city)]
    end
</pre>
<p>
Then:
</p>
<pre>
    { :address =&gt; Address.new(&quot;813 abc st.&quot;, &quot;chicago&quot;) }
      # =&gt; { :address_street =&gt; &quot;813 abc st.&quot;, :address_city =&gt; &quot;chicago&quot; }
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001729-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001729-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2115</span>
2115:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expand_hash_conditions_for_aggregates</span>(<span class="ruby-identifier">attrs</span>)
2116:           <span class="ruby-identifier">expanded_attrs</span> = {}
2117:           <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
2118:             <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">aggregation</span> = <span class="ruby-identifier">reflect_on_aggregation</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_sym</span>)).<span class="ruby-identifier">nil?</span>
2119:               <span class="ruby-identifier">mapping</span> = <span class="ruby-identifier">aggregate_mapping</span>(<span class="ruby-identifier">aggregation</span>)
2120:               <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">field_attr</span>, <span class="ruby-identifier">aggregate_attr</span><span class="ruby-operator">|</span>
2121:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">aggregate_attr</span>)
2122:                   <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">field_attr</span>] = <span class="ruby-identifier">value</span>
2123:                 <span class="ruby-keyword kw">else</span>
2124:                   <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">field_attr</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">aggregate_attr</span>)
2125:                 <span class="ruby-keyword kw">end</span>
2126:               <span class="ruby-keyword kw">end</span>
2127:             <span class="ruby-keyword kw">else</span>
2128:               <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-identifier">value</span>
2129:             <span class="ruby-keyword kw">end</span>
2130:           <span class="ruby-keyword kw">end</span>
2131:           <span class="ruby-identifier">expanded_attrs</span>
2132:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001732" class="method-detail">
        <a name="M001732"></a>

        <div class="method-heading">
          <a href="#M001732" class="method-signature">
          <span class="method-name">sanitize_sql_array</span><span class="method-args">(ary)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array of conditions. The array has each value sanitized and
interpolated into the SQL statement.
</p>
<pre>
  [&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001732-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001732-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2183</span>
2183:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">ary</span>)
2184:           <span class="ruby-identifier">statement</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">values</span> = <span class="ruby-identifier">ary</span>
2185:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">statement</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/:\w+/</span>
2186:             <span class="ruby-identifier">replace_named_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
2187:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'?'</span>)
2188:             <span class="ruby-identifier">replace_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
2189:           <span class="ruby-keyword kw">else</span>
2190:             <span class="ruby-identifier">statement</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_string</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>) }
2191:           <span class="ruby-keyword kw">end</span>
2192:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001727" class="method-detail">
        <a name="M001727"></a>

        <div class="method-heading">
          <a href="#M001727" class="method-signature">
          <span class="method-name">sanitize_sql_for_assignment</span><span class="method-args">(assignments)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array, <a href="Base.html#M001767">hash</a>, or string of SQL
conditions and sanitizes them into a valid SQL fragment for a SET clause.
</p>
<pre>
  { :name =&gt; nil, :group_id =&gt; 4 }  returns &quot;name = NULL , group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001727-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001727-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2091</span>
2091:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_for_assignment</span>(<span class="ruby-identifier">assignments</span>)
2092:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">assignments</span>
2093:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">assignments</span>)
2094:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">assignments</span>)
2095:             <span class="ruby-keyword kw">else</span>        <span class="ruby-identifier">assignments</span>
2096:           <span class="ruby-keyword kw">end</span>
2097:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001726" class="method-detail">
        <a name="M001726"></a>

        <div class="method-heading">
          <a href="#M001726" class="method-signature">
          <span class="method-name">sanitize_sql_for_conditions</span><span class="method-args">(condition, table_name = quoted_table_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Accepts an array, <a href="Base.html#M001767">hash</a>, or string of SQL
conditions and sanitizes them into a valid SQL fragment for a WHERE clause.
</p>
<pre>
  [&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
  { :name =&gt; &quot;foo'bar&quot;, :group_id =&gt; 4 }  returns &quot;name='foo''bar' and group_id='4'&quot;
  &quot;name='foo''bar' and group_id='4'&quot; returns &quot;name='foo''bar' and group_id='4'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001726-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001726-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2077</span>
2077:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_for_conditions</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">table_name</span> = <span class="ruby-identifier">quoted_table_name</span>)
2078:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">condition</span>.<span class="ruby-identifier">blank?</span>
2079: 
2080:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">condition</span>
2081:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">condition</span>)
2082:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">table_name</span>)
2083:             <span class="ruby-keyword kw">else</span>        <span class="ruby-identifier">condition</span>
2084:           <span class="ruby-keyword kw">end</span>
2085:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001731" class="method-detail">
        <a name="M001731"></a>

        <div class="method-heading">
          <a href="#M001731" class="method-signature">
          <span class="method-name">sanitize_sql_hash_for_assignment</span><span class="method-args">(attrs)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sanitizes a <a href="Base.html#M001767">hash</a> of attribute/value pairs
into SQL conditions for a SET clause.
</p>
<pre>
  { :status =&gt; nil, :group_id =&gt; 1 }
    # =&gt; &quot;status = NULL , group_id = 1&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001731-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001731-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2174</span>
2174:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">attrs</span>)
2175:           <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
2176:             <span class="ruby-node">&quot;#{connection.quote_column_name(attr)} = #{quote_bound_value(value)}&quot;</span>
2177:           <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">', '</span>)
2178:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001730" class="method-detail">
        <a name="M001730"></a>

        <div class="method-heading">
          <a href="#M001730" class="method-signature">
          <span class="method-name">sanitize_sql_hash_for_conditions</span><span class="method-args">(attrs, table_name = quoted_table_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sanitizes a <a href="Base.html#M001767">hash</a> of attribute/value pairs
into SQL conditions for a WHERE clause.
</p>
<pre>
  { :name =&gt; &quot;foo'bar&quot;, :group_id =&gt; 4 }
    # =&gt; &quot;name='foo''bar' and group_id= 4&quot;
  { :status =&gt; nil, :group_id =&gt; [1,2,3] }
    # =&gt; &quot;status IS NULL and group_id IN (1,2,3)&quot;
  { :age =&gt; 13..18 }
    # =&gt; &quot;age BETWEEN 13 AND 18&quot;
  { 'other_records.id' =&gt; 7 }
    # =&gt; &quot;`other_records`.`id` = 7&quot;
  { :other_records =&gt; { :id =&gt; 7 } }
    # =&gt; &quot;`other_records`.`id` = 7&quot;
</pre>
<p>
And for value objects on a composed_of relationship:
</p>
<pre>
  { :address =&gt; Address.new(&quot;123 abc st.&quot;, &quot;chicago&quot;) }
    # =&gt; &quot;address_street='123 abc st.' and address_city='chicago'&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001730-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001730-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2148</span>
2148:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">table_name</span> = <span class="ruby-identifier">quoted_table_name</span>)
2149:           <span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">expand_hash_conditions_for_aggregates</span>(<span class="ruby-identifier">attrs</span>)
2150: 
2151:           <span class="ruby-identifier">conditions</span> = <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
2152:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
2153:               <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>
2154: 
2155:               <span class="ruby-comment cmt"># Extract table name from qualified attribute names.</span>
2156:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'.'</span>)
2157:                 <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>, <span class="ruby-value">2</span>)
2158:                 <span class="ruby-identifier">table_name</span> = <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_table_name</span>(<span class="ruby-identifier">table_name</span>)
2159:               <span class="ruby-keyword kw">end</span>
2160: 
2161:               <span class="ruby-node">&quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;</span>
2162:             <span class="ruby-keyword kw">else</span>
2163:               <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_table_name</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>))
2164:             <span class="ruby-keyword kw">end</span>
2165:           <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">' AND '</span>)
2166: 
2167:           <span class="ruby-identifier">replace_bind_variables</span>(<span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">expand_range_bind_variables</span>(<span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">values</span>))
2168:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001723" class="method-detail">
        <a name="M001723"></a>

        <div class="method-heading">
          <a href="#M001723" class="method-signature">
          <span class="method-name">with_exclusive_scope</span><span class="method-args">(method_scoping = {}, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works like <a href="Base.html#M001722">with_scope</a>, but discards any
nested properties.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001723-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001723-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2012</span>
2012:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_exclusive_scope</span>(<span class="ruby-identifier">method_scoping</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
2013:           <span class="ruby-identifier">with_scope</span>(<span class="ruby-identifier">method_scoping</span>, <span class="ruby-identifier">:overwrite</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
2014:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001722" class="method-detail">
        <a name="M001722"></a>

        <div class="method-heading">
          <a href="#M001722" class="method-signature">
          <span class="method-name">with_scope</span><span class="method-args">(method_scoping = {}, action = :merge) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Scope parameters to method calls within the block. Takes a <a
href="Base.html#M001767">hash</a> of method_name =&gt; parameters <a
href="Base.html#M001767">hash</a>. method_name may be <tt>:<a
href="Base.html#M001674">find</a></tt> or <tt>:<a
href="Base.html#M001680">create</a></tt>. <tt>:<a
href="Base.html#M001674">find</a></tt> parameters may include the
<tt>:conditions</tt>, <tt>:joins</tt>, <tt>:include</tt>, <tt>:offset</tt>,
<tt>:limit</tt>, and <tt>:readonly</tt> options. <tt>:<a
href="Base.html#M001680">create</a></tt> parameters are an <a
href="Base.html#M001758">attributes</a> <a
href="Base.html#M001767">hash</a>.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.create_with_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot; }, :create =&gt; { :blog_id =&gt; 1 }) do
        find(1) # =&gt; SELECT * from articles WHERE blog_id = 1 AND id = 1
        a = create(1)
        a.blog_id # =&gt; 1
      end
    end
  end
</pre>
<p>
In nested scopings, <a href="Base.html#M001677">all</a> previous parameters
are overwritten by the innermost rule, with the exception of
<tt>:conditions</tt> and <tt>:include</tt> options in <tt>:<a
href="Base.html#M001674">find</a></tt>, which are merged.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.find_with_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot;, :limit =&gt; 1 }, :create =&gt; { :blog_id =&gt; 1 }) do
        with_scope(:find =&gt; { :limit =&gt; 10 })
          find(:all) # =&gt; SELECT * from articles WHERE blog_id = 1 LIMIT 10
        end
        with_scope(:find =&gt; { :conditions =&gt; &quot;author_id = 3&quot; })
          find(:all) # =&gt; SELECT * from articles WHERE blog_id = 1 AND author_id = 3 LIMIT 1
        end
      end
    end
  end
</pre>
<p>
You can ignore any previous scopings by using the <tt><a
href="Base.html#M001723">with_exclusive_scope</a></tt> method.
</p>
<pre>
  class Article &lt; ActiveRecord::Base
    def self.find_with_exclusive_scope
      with_scope(:find =&gt; { :conditions =&gt; &quot;blog_id = 1&quot;, :limit =&gt; 1 }) do
        with_exclusive_scope(:find =&gt; { :limit =&gt; 10 })
          find(:all) # =&gt; SELECT * from articles LIMIT 10
        end
      end
    end
  end
</pre>
<p>
<b>Note</b>: the +:<a href="Base.html#M001674">find</a>+ scope also has
effect on <a href="Base.html#M001681">update</a> and deletion methods, like
<tt><a href="Base.html#M001684">update_all</a></tt> and <tt><a
href="Base.html#M001686">delete_all</a></tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001722-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001722-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 1958</span>
1958:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_scope</span>(<span class="ruby-identifier">method_scoping</span> = {}, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">:merge</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1959:           <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">method_scoping</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:method_scoping</span>)
1960: 
1961:           <span class="ruby-comment cmt"># Dup first and second level of hash (method and params).</span>
1962:           <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, (<span class="ruby-identifier">method</span>, <span class="ruby-identifier">params</span>)<span class="ruby-operator">|</span>
1963:             <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = (<span class="ruby-identifier">params</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">params</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">dup</span>
1964:             <span class="ruby-identifier">hash</span>
1965:           <span class="ruby-keyword kw">end</span>
1966: 
1967:           <span class="ruby-identifier">method_scoping</span>.<span class="ruby-identifier">assert_valid_keys</span>([ <span class="ruby-identifier">:find</span>, <span class="ruby-identifier">:create</span> ])
1968: 
1969:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">f</span> = <span class="ruby-identifier">method_scoping</span>[<span class="ruby-identifier">:find</span>]
1970:             <span class="ruby-identifier">f</span>.<span class="ruby-identifier">assert_valid_keys</span>(<span class="ruby-constant">VALID_FIND_OPTIONS</span>)
1971:             <span class="ruby-identifier">set_readonly_option!</span> <span class="ruby-identifier">f</span>
1972:           <span class="ruby-keyword kw">end</span>
1973: 
1974:           <span class="ruby-comment cmt"># Merge scopings</span>
1975:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">action</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:merge</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">current_scoped_methods</span>
1976:             <span class="ruby-identifier">method_scoping</span> = <span class="ruby-identifier">current_scoped_methods</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">method_scoping</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, (<span class="ruby-identifier">method</span>, <span class="ruby-identifier">params</span>)<span class="ruby-operator">|</span>
1977:               <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>]
1978:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
1979:                   <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:find</span>
1980:                     (<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>].<span class="ruby-identifier">keys</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">keys</span>).<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
1981:                       <span class="ruby-identifier">merge</span> = <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>] <span class="ruby-comment cmt"># merge if both scopes have the same key</span>
1982:                       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:conditions</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">merge</span>
1983:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">merge_conditions</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>], <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>])
1984:                       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:include</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">merge</span>
1985:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">merge_includes</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>], <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>]).<span class="ruby-identifier">uniq</span>
1986:                       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:joins</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">merge</span>
1987:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">merge_joins</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>], <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>])
1988:                       <span class="ruby-keyword kw">else</span>
1989:                         <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>][<span class="ruby-identifier">key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">key</span>]
1990:                       <span class="ruby-keyword kw">end</span>
1991:                     <span class="ruby-keyword kw">end</span>
1992:                   <span class="ruby-keyword kw">else</span>
1993:                     <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>])
1994:                   <span class="ruby-keyword kw">end</span>
1995:                 <span class="ruby-keyword kw">else</span>
1996:                   <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">method</span>] = <span class="ruby-identifier">params</span>
1997:               <span class="ruby-keyword kw">end</span>
1998:               <span class="ruby-identifier">hash</span>
1999:             <span class="ruby-keyword kw">end</span>
2000:           <span class="ruby-keyword kw">end</span>
2001: 
2002:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scoped_methods</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">method_scoping</span>
2003: 
2004:           <span class="ruby-keyword kw">begin</span>
2005:             <span class="ruby-keyword kw">yield</span>
2006:           <span class="ruby-keyword kw">ensure</span>
2007:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scoped_methods</span>.<span class="ruby-identifier">pop</span>
2008:           <span class="ruby-keyword kw">end</span>
2009:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001765" class="method-detail">
        <a name="M001765"></a>

        <div class="method-heading">
          <a href="#M001765" class="method-signature">
          <span class="method-name">==</span><span class="method-args">(comparison_object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the <tt>comparison_object</tt> is the same object, or is of
the same type and has the same <a href="Base.html#M001734">id</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001765-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001765-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2649</span>
2649:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">comparison_object</span>)
2650:         <span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">||</span>
2651:           (<span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&amp;&amp;</span>
2652:             <span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span> <span class="ruby-operator">&amp;&amp;</span>
2653:             <span class="ruby-operator">!</span><span class="ruby-identifier">comparison_object</span>.<span class="ruby-identifier">new_record?</span>)
2654:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001755" class="method-detail">
        <a name="M001755"></a>

        <div class="method-heading">
          <a href="#M001755" class="method-signature">
          <span class="method-name">[]</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the value of the attribute identified by <tt>attr_name</tt> after
it has been typecast (for example, &quot;2004-12-12&quot; in a data column
is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the
protected read_attribute method).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001755-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001755-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2547</span>
2547:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">attr_name</span>)
2548:         <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attr_name</span>)
2549:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001756" class="method-detail">
        <a name="M001756"></a>

        <div class="method-heading">
          <a href="#M001756" class="method-signature">
          <span class="method-name">[]=</span><span class="method-args">(attr_name, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates the attribute identified by <tt>attr_name</tt> with the specified
<tt>value</tt>. (Alias for the protected write_attribute method).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001756-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001756-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2553</span>
2553:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">value</span>)
2554:         <span class="ruby-identifier">write_attribute</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">value</span>)
2555:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001760" class="method-detail">
        <a name="M001760"></a>

        <div class="method-heading">
          <a href="#M001760" class="method-signature">
          <span class="method-name">attribute_for_inspect</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Format <a href="Base.html#M001758">attributes</a> nicely for <a
href="Base.html#M001713">inspect</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001760-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001760-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2614</span>
2614:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_for_inspect</span>(<span class="ruby-identifier">attr_name</span>)
2615:         <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attr_name</span>)
2616: 
2617:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">50</span>
2618:           <span class="ruby-node">&quot;#{value[0..50]}...&quot;</span>.<span class="ruby-identifier">inspect</span>
2619:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Date</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Time</span>)
2620:           <span class="ruby-node">%(&quot;#{value.to_s(:db)}&quot;)</span>
2621:         <span class="ruby-keyword kw">else</span>
2622:           <span class="ruby-identifier">value</span>.<span class="ruby-identifier">inspect</span>
2623:         <span class="ruby-keyword kw">end</span>
2624:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001763" class="method-detail">
        <a name="M001763"></a>

        <div class="method-heading">
          <a href="#M001763" class="method-signature">
          <span class="method-name">attribute_names</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of names for the <a
href="Base.html#M001758">attributes</a> available on this object sorted
alphabetically.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001763-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001763-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2639</span>
2639:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_names</span>
2640:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>
2641:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001761" class="method-detail">
        <a name="M001761"></a>

        <div class="method-heading">
          <a href="#M001761" class="method-signature">
          <span class="method-name">attribute_present?</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the specified <tt>attribute</tt> has been set by the user
or by a database load and is neither nil nor empty? (the latter only
applies to objects that respond to empty?, most notably Strings).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001761-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001761-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2628</span>
2628:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attribute_present?</span>(<span class="ruby-identifier">attribute</span>)
2629:         <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">attribute</span>)
2630:         <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">blank?</span>
2631:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001758" class="method-detail">
        <a name="M001758"></a>

        <div class="method-heading">
          <a href="#M001758" class="method-signature">
          <span class="method-name">attributes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001767">hash</a> of <a
href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> with their names as keys and the
values of the <a href="Base.html#M001758">attributes</a> as values.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001758-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001758-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2598</span>
2598:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes</span>
2599:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attribute_names</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
2600:           <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-identifier">name</span>)
2601:           <span class="ruby-identifier">attrs</span>
2602:         <span class="ruby-keyword kw">end</span>
2603:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001757" class="method-detail">
        <a name="M001757"></a>

        <div class="method-heading">
          <a href="#M001757" class="method-signature">
          <span class="method-name">attributes=</span><span class="method-args">(new_attributes, guard_protected_attributes = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Allows you to set <a href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> at once by passing in a <a
href="Base.html#M001767">hash</a> with keys matching the attribute names
(which again matches the column names).
</p>
<p>
If <tt>guard_protected_attributes</tt> is true (the default), then
sensitive <a href="Base.html#M001758">attributes</a> can be protected from
this form of mass-assignment by using the <tt><a
href="Base.html#M001691">attr_protected</a></tt> macro. Or you can
alternatively specify which <a href="Base.html#M001758">attributes</a>
<b>can</b> be accessed with the <tt><a
href="Base.html#M001692">attr_accessible</a></tt> macro. Then <a
href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> not included in that won&#8216;t be
allowed to be mass-assigned.
</p>
<pre>
  class User &lt; ActiveRecord::Base
    attr_protected :is_admin
  end

  user = User.new
  user.attributes = { :username =&gt; 'Phusion', :is_admin =&gt; true }
  user.username   # =&gt; &quot;Phusion&quot;
  user.is_admin?  # =&gt; false

  user.send(:attributes=, { :username =&gt; 'Phusion', :is_admin =&gt; true }, false)
  user.is_admin?  # =&gt; true
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001757-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001757-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2577</span>
2577:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes=</span>(<span class="ruby-identifier">new_attributes</span>, <span class="ruby-identifier">guard_protected_attributes</span> = <span class="ruby-keyword kw">true</span>)
2578:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_attributes</span>.<span class="ruby-identifier">nil?</span>
2579:         <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">new_attributes</span>.<span class="ruby-identifier">dup</span>
2580:         <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">stringify_keys!</span>
2581: 
2582:         <span class="ruby-identifier">multi_parameter_attributes</span> = []
2583:         <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">remove_attributes_protected_from_mass_assignment</span>(<span class="ruby-identifier">attributes</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">guard_protected_attributes</span>
2584: 
2585:         <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
2586:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">&quot;(&quot;</span>)
2587:             <span class="ruby-identifier">multi_parameter_attributes</span> <span class="ruby-operator">&lt;&lt;</span> [ <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span> ]
2588:           <span class="ruby-keyword kw">else</span>
2589:             <span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">&quot;#{k}=&quot;</span><span class="ruby-node">&quot;#{k}=&quot;</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{k}=&quot;</span><span class="ruby-node">&quot;#{k}=&quot;</span>, <span class="ruby-identifier">v</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">UnknownAttributeError</span>, <span class="ruby-node">&quot;unknown attribute: #{k}&quot;</span>)
2590:           <span class="ruby-keyword kw">end</span>
2591:         <span class="ruby-keyword kw">end</span>
2592: 
2593:         <span class="ruby-identifier">assign_multiparameter_attributes</span>(<span class="ruby-identifier">multi_parameter_attributes</span>)
2594:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001759" class="method-detail">
        <a name="M001759"></a>

        <div class="method-heading">
          <a href="#M001759" class="method-signature">
          <span class="method-name">attributes_before_type_cast</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001767">hash</a> of <a
href="Base.html#M001758">attributes</a> before typecasting and
deserialization.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001759-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001759-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2606</span>
2606:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attributes_before_type_cast</span>
2607:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attribute_names</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
2608:           <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">read_attribute_before_type_cast</span>(<span class="ruby-identifier">name</span>)
2609:           <span class="ruby-identifier">attrs</span>
2610:         <span class="ruby-keyword kw">end</span>
2611:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001744" class="method-detail">
        <a name="M001744"></a>

        <div class="method-heading">
          <a href="#M001744" class="method-signature">
          <span class="method-name">becomes</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an instance of the specified <tt>klass</tt> with the <a
href="Base.html#M001758">attributes</a> of the current record. This is
mostly useful in relation to single-table inheritance structures where you
want a subclass to appear as the superclass. This can be used along with
record identification in Action Pack to allow, say, <tt>Client &lt;
Company</tt> to do something like render <tt>:partial =&gt;
@client.becomes(Company)</tt> to render that instance using the
companies/company partial instead of clients/client.
</p>
<p>
Note: The <a href="Base.html#M001733">new</a> instance will share a link to
the same <a href="Base.html#M001758">attributes</a> as the original class.
So any change to the <a href="Base.html#M001758">attributes</a> in either
instance will affect the other.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001744-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001744-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2452</span>
2452:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">becomes</span>(<span class="ruby-identifier">klass</span>)
2453:         <span class="ruby-identifier">returning</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">became</span><span class="ruby-operator">|</span>
2454:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@attributes&quot;</span>, <span class="ruby-ivar">@attributes</span>)
2455:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@attributes_cache&quot;</span>, <span class="ruby-ivar">@attributes_cache</span>)
2456:           <span class="ruby-identifier">became</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@new_record&quot;</span>, <span class="ruby-identifier">new_record?</span>)
2457:         <span class="ruby-keyword kw">end</span>
2458:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001736" class="method-detail">
        <a name="M001736"></a>

        <div class="method-heading">
          <a href="#M001736" class="method-signature">
          <span class="method-name">cache_key</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a cache key that can be used to identify this record.
</p>
<h4>Examples</h4>
<pre>
  Product.new.cache_key     # =&gt; &quot;products/new&quot;
  Product.find(5).cache_key # =&gt; &quot;products/5&quot; (updated_at not available)
  Person.find(5).cache_key  # =&gt; &quot;people/5-20071224150000&quot; (updated_at available)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001736-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001736-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2338</span>
2338:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_key</span>
2339:         <span class="ruby-keyword kw">case</span>
2340:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">new_record?</span>
2341:           <span class="ruby-node">&quot;#{self.class.model_name.cache_key}/new&quot;</span>
2342:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">timestamp</span> = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">:updated_at</span>]
2343:           <span class="ruby-node">&quot;#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}&quot;</span>
2344:         <span class="ruby-keyword kw">else</span>
2345:           <span class="ruby-node">&quot;#{self.class.model_name.cache_key}/#{id}&quot;</span>
2346:         <span class="ruby-keyword kw">end</span>
2347:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001743" class="method-detail">
        <a name="M001743"></a>

        <div class="method-heading">
          <a href="#M001743" class="method-signature">
          <span class="method-name">clone</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Base.html#M001743">clone</a> of the record that
hasn&#8216;t been assigned an <a href="Base.html#M001734">id</a> yet and is
treated as a <a href="Base.html#M001733">new</a> record. Note that this is
a &quot;shallow&quot; <a href="Base.html#M001743">clone</a>: it copies the
object&#8216;s <a href="Base.html#M001758">attributes</a> only, not its
associations. The extent of a &quot;deep&quot; <a
href="Base.html#M001743">clone</a> is application-specific and is therefore
left to the application to implement according to its need.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001743-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001743-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2437</span>
2437:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clone</span>
2438:         <span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">clone_attributes</span>(<span class="ruby-identifier">:read_attribute_before_type_cast</span>)
2439:         <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>)
2440:         <span class="ruby-identifier">record</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>
2441:         <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">:instance_variable_set</span>, <span class="ruby-value str">'@attributes'</span>, <span class="ruby-identifier">attrs</span>
2442:         <span class="ruby-identifier">record</span>
2443:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001764" class="method-detail">
        <a name="M001764"></a>

        <div class="method-heading">
          <a href="#M001764" class="method-signature">
          <span class="method-name">column_for_attribute</span><span class="method-args">(name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the column object for the named attribute.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001764-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001764-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2644</span>
2644:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">column_for_attribute</span>(<span class="ruby-identifier">name</span>)
2645:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>]
2646:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001773" class="method-detail">
        <a name="M001773"></a>

        <div class="method-heading">
          <a href="#M001773" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Base.html#M001773">connection</a> currently associated
with the class. This can also be used to &quot;borrow&quot; the <a
href="Base.html#M001773">connection</a> to do database work that
isn&#8216;t easily done without going straight to SQL.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001773-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001773-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb, line 17</span>
17:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>
18:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">connection</span>
19:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001750" class="method-detail">
        <a name="M001750"></a>

        <div class="method-heading">
          <a href="#M001750" class="method-signature">
          <span class="method-name">decrement</span><span class="method-args">(attribute, by = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Initializes <tt>attribute</tt> to zero if <tt>nil</tt> and subtracts the
value passed as <tt>by</tt> (default is 1). The <a
href="Base.html#M001750">decrement</a> is performed directly on the
underlying attribute, no setter is invoked. Only makes sense for
number-based <a href="Base.html#M001758">attributes</a>. Returns
<tt>self</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001750-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001750-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2501</span>
2501:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span> = <span class="ruby-value">1</span>)
2502:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
2503:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">-=</span> <span class="ruby-identifier">by</span>
2504:         <span class="ruby-keyword kw">self</span>
2505:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001751" class="method-detail">
        <a name="M001751"></a>

        <div class="method-heading">
          <a href="#M001751" class="method-signature">
          <span class="method-name">decrement!</span><span class="method-args">(attribute, by = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Wrapper around <tt><a href="Base.html#M001750">decrement</a></tt> that
saves the record. This method differs from its non-bang version in that it
passes through the attribute setter. Saving is not subjected to validation
checks. Returns <tt>true</tt> if the record could be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001751-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001751-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2511</span>
2511:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrement!</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span> = <span class="ruby-value">1</span>)
2512:         <span class="ruby-identifier">decrement</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2513:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001741" class="method-detail">
        <a name="M001741"></a>

        <div class="method-heading">
          <a href="#M001741" class="method-signature">
          <span class="method-name">delete</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the record in the database and freezes this instance to reflect
that no changes should be made (since they can&#8216;t be persisted).
</p>
<p>
Unlike <a href="Base.html#M001683">destroy</a>, this method doesn&#8216;t
run any <tt>before_delete</tt> and <tt>after_delete</tt> callbacks, nor
will it enforce any association +:dependent+ rules.
</p>
<p>
In addition to deleting this record, any defined <tt>before_delete</tt> and
<tt>after_delete</tt> callbacks are run, and +:dependent+ rules defined on
associations are run.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001741-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001741-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2413</span>
2413:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>
2414:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">id</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">new_record?</span>
2415:         <span class="ruby-identifier">freeze</span>
2416:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001742" class="method-detail">
        <a name="M001742"></a>

        <div class="method-heading">
          <a href="#M001742" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the record in the database and freezes this instance to reflect
that no changes should be made (since they can&#8216;t be persisted).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001742-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001742-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2420</span>
2420:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>
2421:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">new_record?</span>
2422:           <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span>(
2423:             <span class="ruby-node">&quot;DELETE FROM #{self.class.quoted_table_name} &quot;</span> <span class="ruby-operator">+</span>
2424:             <span class="ruby-node">&quot;WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id}&quot;</span>,
2425:             <span class="ruby-node">&quot;#{self.class.name} Destroy&quot;</span>
2426:           )
2427:         <span class="ruby-keyword kw">end</span>
2428: 
2429:         <span class="ruby-identifier">freeze</span>
2430:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001766" class="method-detail">
        <a name="M001766"></a>

        <div class="method-heading">
          <a href="#M001766" class="method-signature">
          <span class="method-name">eql?</span><span class="method-args">(comparison_object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delegates to ==
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001766-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001766-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2657</span>
2657:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">comparison_object</span>)
2658:         <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">comparison_object</span>)
2659:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001768" class="method-detail">
        <a name="M001768"></a>

        <div class="method-heading">
          <a href="#M001768" class="method-signature">
          <span class="method-name">freeze</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Freeze the <a href="Base.html#M001758">attributes</a> <a
href="Base.html#M001767">hash</a> such that associations are still
accessible, even on destroyed records.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001768-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001768-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2668</span>
2668:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">freeze</span>
2669:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">freeze</span>; <span class="ruby-keyword kw">self</span>
2670:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001769" class="method-detail">
        <a name="M001769"></a>

        <div class="method-heading">
          <a href="#M001769" class="method-signature">
          <span class="method-name">frozen?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>true</tt> if the <a href="Base.html#M001758">attributes</a> <a
href="Base.html#M001767">hash</a> has been frozen.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001769-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001769-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2673</span>
2673:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">frozen?</span>
2674:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">frozen?</span>
2675:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001762" class="method-detail">
        <a name="M001762"></a>

        <div class="method-heading">
          <a href="#M001762" class="method-signature">
          <span class="method-name">has_attribute?</span><span class="method-args">(attr_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the given attribute is in the <a
href="Base.html#M001758">attributes</a> <a
href="Base.html#M001767">hash</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001762-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001762-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2634</span>
2634:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_attribute?</span>(<span class="ruby-identifier">attr_name</span>)
2635:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>)
2636:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001767" class="method-detail">
        <a name="M001767"></a>

        <div class="method-heading">
          <a href="#M001767" class="method-signature">
          <span class="method-name">hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delegates to <a href="Base.html#M001734">id</a> in order to allow two
records of the same type and <a href="Base.html#M001734">id</a> to work
with something like:
</p>
<pre>
  [ Person.find(1), Person.find(2), Person.find(3) ] &amp; [ Person.find(1), Person.find(4) ] # =&gt; [ Person.find(1) ]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001767-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001767-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2663</span>
2663:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
2664:         <span class="ruby-identifier">id</span>.<span class="ruby-identifier">hash</span>
2665:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001734" class="method-detail">
        <a name="M001734"></a>

        <div class="method-heading">
          <a href="#M001734" class="method-signature">
          <span class="method-name">id</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A model instance&#8216;s primary key is always available as model.id
whether you name it the default &#8216;<a
href="Base.html#M001734">id</a>&#8217; or set it to something else.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001734-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001734-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2294</span>
2294:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id</span>
2295:         <span class="ruby-identifier">attr_name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>
2296:         <span class="ruby-identifier">column</span> = <span class="ruby-identifier">column_for_attribute</span>(<span class="ruby-identifier">attr_name</span>)
2297: 
2298:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:define_read_method</span>, <span class="ruby-identifier">:id</span>, <span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">column</span>)
2299:         <span class="ruby-comment cmt"># now that the method exists, call it</span>
2300:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_sym</span>
2301: 
2302:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001737" class="method-detail">
        <a name="M001737"></a>

        <div class="method-heading">
          <a href="#M001737" class="method-signature">
          <span class="method-name">id=</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the primary ID.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001737-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001737-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2358</span>
2358:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id=</span>(<span class="ruby-identifier">value</span>)
2359:         <span class="ruby-identifier">write_attribute</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>, <span class="ruby-identifier">value</span>)
2360:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001748" class="method-detail">
        <a name="M001748"></a>

        <div class="method-heading">
          <a href="#M001748" class="method-signature">
          <span class="method-name">increment</span><span class="method-args">(attribute, by = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Initializes <tt>attribute</tt> to zero if <tt>nil</tt> and adds the value
passed as <tt>by</tt> (default is 1). The <a
href="Base.html#M001748">increment</a> is performed directly on the
underlying attribute, no setter is invoked. Only makes sense for
number-based <a href="Base.html#M001758">attributes</a>. Returns
<tt>self</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001748-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001748-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2484</span>
2484:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span> = <span class="ruby-value">1</span>)
2485:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
2486:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] <span class="ruby-operator">+=</span> <span class="ruby-identifier">by</span>
2487:         <span class="ruby-keyword kw">self</span>
2488:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001749" class="method-detail">
        <a name="M001749"></a>

        <div class="method-heading">
          <a href="#M001749" class="method-signature">
          <span class="method-name">increment!</span><span class="method-args">(attribute, by = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Wrapper around <tt><a href="Base.html#M001748">increment</a></tt> that
saves the record. This method differs from its non-bang version in that it
passes through the attribute setter. Saving is not subjected to validation
checks. Returns <tt>true</tt> if the record could be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001749-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001749-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2494</span>
2494:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">increment!</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span> = <span class="ruby-value">1</span>)
2495:         <span class="ruby-identifier">increment</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">by</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2496:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001772" class="method-detail">
        <a name="M001772"></a>

        <div class="method-heading">
          <a href="#M001772" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the contents of the record as a nicely formatted string.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001772-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001772-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2689</span>
2689:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
2690:         <span class="ruby-identifier">attributes_as_nice_string</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
2691:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_attribute?</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">new_record?</span>
2692:             <span class="ruby-node">&quot;#{name}: #{attribute_for_inspect(name)}&quot;</span>
2693:           <span class="ruby-keyword kw">end</span>
2694:         }.<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;, &quot;</span>)
2695:         <span class="ruby-node">&quot;#&lt;#{self.class} #{attributes_as_nice_string}&gt;&quot;</span>
2696:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001738" class="method-detail">
        <a name="M001738"></a>

        <div class="method-heading">
          <a href="#M001738" class="method-signature">
          <span class="method-name">new_record?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if this object hasn&#8216;t been saved yet &#8212; that is, a
record for the object doesn&#8216;t exist yet.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001738-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001738-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2363</span>
2363:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_record?</span>
2364:         <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@new_record</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@new_record</span>
2365:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001771" class="method-detail">
        <a name="M001771"></a>

        <div class="method-heading">
          <a href="#M001771" class="method-signature">
          <span class="method-name">readonly!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Marks this record as read only.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001771-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001771-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2684</span>
2684:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly!</span>
2685:         <span class="ruby-ivar">@readonly</span> = <span class="ruby-keyword kw">true</span>
2686:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001770" class="method-detail">
        <a name="M001770"></a>

        <div class="method-heading">
          <a href="#M001770" class="method-signature">
          <span class="method-name">readonly?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>true</tt> if the record is read only. Records loaded through
joins with piggy-back <a href="Base.html#M001758">attributes</a> will be
marked as read only since they cannot be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001770-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001770-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2679</span>
2679:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readonly?</span>
2680:         <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@readonly</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@readonly</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
2681:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001754" class="method-detail">
        <a name="M001754"></a>

        <div class="method-heading">
          <a href="#M001754" class="method-signature">
          <span class="method-name">reload</span><span class="method-args">(options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reloads the <a href="Base.html#M001758">attributes</a> of this object from
the database. The optional options argument is passed to <a
href="Base.html#M001674">find</a> when reloading so you may do e.g.
record.reload(:lock =&gt; true) to <a href="Base.html#M001754">reload</a>
the same record with an exclusive row lock.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001754-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001754-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2536</span>
2536:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
2537:         <span class="ruby-identifier">clear_aggregation_cache</span>
2538:         <span class="ruby-identifier">clear_association_cache</span>
2539:         <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">update</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">find</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value str">'@attributes'</span>))
2540:         <span class="ruby-ivar">@attributes_cache</span> = {}
2541:         <span class="ruby-keyword kw">self</span>
2542:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001739" class="method-detail">
        <a name="M001739"></a>

        <div class="method-heading">
          <a href="#M001739" class="method-signature">
          <span class="method-name">save(perform_validation = true)<br />
</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves the model.
</p>
<p>
If the model is <a href="Base.html#M001733">new</a> a record gets created
in the database, otherwise the existing record gets updated.
</p>
<p>
If <tt>perform_validation</tt> is true validations run. If any of them fail
the action is cancelled and <tt><a href="Base.html#M001739">save</a></tt>
returns <tt>false</tt>. If the flag is false validations are bypassed
altogether. See <a href="Validations.html">ActiveRecord::Validations</a>
for more information.
</p>
<p>
There&#8216;s a series of callbacks associated with <tt><a
href="Base.html#M001739">save</a></tt>. If any of the <tt>before_*</tt>
callbacks return <tt>false</tt> the action is cancelled and <tt><a
href="Base.html#M001739">save</a></tt> returns <tt>false</tt>. See <a
href="Callbacks.html">ActiveRecord::Callbacks</a> for further details.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001739-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001739-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2384</span>
2384:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>
2385:         <span class="ruby-identifier">create_or_update</span>
2386:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001740" class="method-detail">
        <a name="M001740"></a>

        <div class="method-heading">
          <a href="#M001740" class="method-signature">
          <span class="method-name">save!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves the model.
</p>
<p>
If the model is <a href="Base.html#M001733">new</a> a record gets created
in the database, otherwise the existing record gets updated.
</p>
<p>
With <tt><a href="Base.html#M001740">save!</a></tt> validations always run.
If any of them fail <a
href="RecordInvalid.html">ActiveRecord::RecordInvalid</a> gets raised. See
<a href="Validations.html">ActiveRecord::Validations</a> for more
information.
</p>
<p>
There&#8216;s a series of callbacks associated with <tt><a
href="Base.html#M001740">save!</a></tt>. If any of the <tt>before_*</tt>
callbacks return <tt>false</tt> the action is cancelled and <tt><a
href="Base.html#M001740">save!</a></tt> raises <a
href="RecordNotSaved.html">ActiveRecord::RecordNotSaved</a>. See <a
href="Callbacks.html">ActiveRecord::Callbacks</a> for further details.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001740-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001740-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2401</span>
2401:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save!</span>
2402:         <span class="ruby-identifier">create_or_update</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RecordNotSaved</span>)
2403:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001735" class="method-detail">
        <a name="M001735"></a>

        <div class="method-heading">
          <a href="#M001735" class="method-signature">
          <span class="method-name">to_param</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a String, which Action Pack uses for constructing an URL to this
object. The default implementation returns this record&#8216;s <a
href="Base.html#M001734">id</a> as a String, or nil if this record&#8216;s
unsaved.
</p>
<p>
For example, suppose that you have a Users model, and that you have a
<tt>map.resources :users</tt> route. Normally, <tt>users_path</tt> will
construct an URI with the user object&#8216;s &#8216;<a
href="Base.html#M001734">id</a>&#8217; in it:
</p>
<pre>
  user = User.find_by_name('Phusion')
  user_path(path)  # =&gt; &quot;/users/1&quot;
</pre>
<p>
You can override <tt><a href="Base.html#M001735">to_param</a></tt> in your
model to make <tt>users_path</tt> construct an URI using the user&#8216;s
name instead of the user&#8216;s <a href="Base.html#M001734">id</a>:
</p>
<pre>
  class User &lt; ActiveRecord::Base
    def to_param  # overridden
      name
    end
  end

  user = User.find_by_name('Phusion')
  user_path(path)  # =&gt; &quot;/users/Phusion&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001735-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001735-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2326</span>
2326:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_param</span>
2327:         <span class="ruby-comment cmt"># We can't use alias_method here, because method 'id' optimizes itself on the fly.</span>
2328:         (<span class="ruby-identifier">id</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># Be sure to stringify the id for routes</span>
2329:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001752" class="method-detail">
        <a name="M001752"></a>

        <div class="method-heading">
          <a href="#M001752" class="method-signature">
          <span class="method-name">toggle</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Assigns to <tt>attribute</tt> the boolean opposite of <tt>attribute?</tt>.
So if the predicate returns <tt>true</tt> the attribute will become
<tt>false</tt>. This method toggles directly the underlying value without
calling any setter. Returns <tt>self</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001752-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001752-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2519</span>
2519:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">toggle</span>(<span class="ruby-identifier">attribute</span>)
2520:         <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>] = <span class="ruby-operator">!</span><span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{attribute}?&quot;</span>)
2521:         <span class="ruby-keyword kw">self</span>
2522:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001753" class="method-detail">
        <a name="M001753"></a>

        <div class="method-heading">
          <a href="#M001753" class="method-signature">
          <span class="method-name">toggle!</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Wrapper around <tt><a href="Base.html#M001752">toggle</a></tt> that saves
the record. This method differs from its non-bang version in that it passes
through the attribute setter. Saving is not subjected to validation checks.
Returns <tt>true</tt> if the record could be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001753-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001753-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2528</span>
2528:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">toggle!</span>(<span class="ruby-identifier">attribute</span>)
2529:         <span class="ruby-identifier">toggle</span>(<span class="ruby-identifier">attribute</span>).<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">attribute</span>])
2530:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001745" class="method-detail">
        <a name="M001745"></a>

        <div class="method-heading">
          <a href="#M001745" class="method-signature">
          <span class="method-name">update_attribute</span><span class="method-args">(name, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates a single attribute and saves the record without going through the
normal validation procedure. This is especially useful for boolean flags on
existing records. The regular <tt><a
href="Base.html#M001745">update_attribute</a></tt> method in <a
href="Base.html">Base</a> is replaced with this when the validations module
is mixed in, which it is by default.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001745-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001745-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2463</span>
2463:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
2464:         <span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'='</span>, <span class="ruby-identifier">value</span>)
2465:         <span class="ruby-identifier">save</span>(<span class="ruby-keyword kw">false</span>)
2466:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001746" class="method-detail">
        <a name="M001746"></a>

        <div class="method-heading">
          <a href="#M001746" class="method-signature">
          <span class="method-name">update_attributes</span><span class="method-args">(attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates <a href="Base.html#M001677">all</a> the <a
href="Base.html#M001758">attributes</a> from the passed-in Hash and saves
the record. If the object is invalid, the saving will fail and false will
be returned.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001746-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001746-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2470</span>
2470:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">attributes</span>)
2471:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span>
2472:         <span class="ruby-identifier">save</span>
2473:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001747" class="method-detail">
        <a name="M001747"></a>

        <div class="method-heading">
          <a href="#M001747" class="method-signature">
          <span class="method-name">update_attributes!</span><span class="method-args">(attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates an object just like <a
href="Base.html#M001746">Base.update_attributes</a> but calls <a
href="Base.html#M001740">save!</a> instead of <a
href="Base.html#M001739">save</a> so an exception is raised if the record
is invalid.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001747-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001747-source">
<pre>
      <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/base.rb, line 2476</span>
2476:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_attributes!</span>(<span class="ruby-identifier">attributes</span>)
2477:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">attributes</span>
2478:         <span class="ruby-identifier">save!</span>
2479:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>